Skip to main content

Exception Cross-thread

Exception:- Cross-thread operation not valid: Control 'treeView' accessed from a thread other than the thread it was created on.

I have kept treeview, You can replace it with control of your choice

Solution

  if (treeView.InvokeRequired)
                    {
                        this.Invoke((MethodInvoker)delegate()
                        {
                         
                            tn = treeView.SelectedNode;
                          
                        });
                    }

This website helped me a lot http://www.daniweb.com/forums/thread285535.html

Check the solution by Farooqaaa: http://www.daniweb.com/forums/post1228357.html#post1228357

Comments

Popular posts from this blog

Static Keyword in C#, unleashing Static keyword in C#

What is Static keyword in C# “Static” keyword can be used for declaring a static member . The keyword Static can be applied to the Classes, field, method, properties, operator, event and constructors. Methods and variable  which we use as static doesn't need an instance to be created of a class. Example of static keyword class testclass {     public static int statint;     public static void squareroot(); } we can call the above static method and variable without creating the instance of the class How to call a static method  testclass.squareroot(); apart from this the static method can use only the static variables of same class.

delete service in windows server 2008/server 2003/xp/ vista

How to delete a service in windows server 2008/server 2003/xp/ vista. Note: There are some services which are system specific and cannot be stopped, Be careful while deleting a service The command to delete the service is "sc delete " The above command executes in DOS prompt.  An error will will come when you execute this command: "[SC] OpenService FAILED 5:" To remove this error and to execute the command in good manner.  When you open the command prompt , run it as administrator and then type : "sc delete " This is how to delete the service Start/Stop the service  You  can also start the service by Control panel-->administrative tools--> Services Right Click on the selected service and start/stop it Ps Note: Before deleting a service in windows server 2008/server 2003/xp/ vista you should confirm the name of service and research in google the effect after you  delete a service. It is difficult to recall the service back...

string is null or empty(String.IsNullOrEmpty)

You can check for the strings in the code, There are many things which  you have to consider before you use a string. Declare the string variable and assign it if (String.IsNullOrEmpty(StringVariable)) {   return "is null or empty" ; else return String.Format( "(\"{0}\") is neither null nor empty" , s); } This will check if the string is null or empty and will return a boolean response.