yaniv Posted November 20, 2014 Posted November 20, 2014 I created some kind of surfing control application. The application open a form, get from the user cardinals, and then it close up and run background thread that sends information about the surfing activity to logger. Sometimes there is a need, of course, to open again the form to change settings� but since the back ground thread is a different thread, there is no way to open the "same" form again, nor close the net listener, each try to do so and with exception that generally says that you can't control the main process from another thread. I can't create new instance of the main form, since the network card is "busy" with the first process. I found that code that open the main form again- CaptureForm cf = new CaptureForm(); showHide = true; cf.Show(); Application.Run(); It does open the same main form, but the background thread are still collision. And any try to make changes to the running threads (like stop the capture of network movements) end with the same exceptions� I have to open the form from the background thread, since it's the only communication I have with the application after the form close. How can I catch the mainform? Or change anything in the background running threads? Quote
Administrators PlausiblyDamp Posted November 20, 2014 Administrators Posted November 20, 2014 Rather than close the form couldn't you keep it open but hidden? That way you would be able to maintain a reference to it at all times and use the .Invoke() method to handle cross thread calls. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
yaniv Posted November 21, 2014 Author Posted November 21, 2014 the invoke is good idea. thanks. but how do i maintain refference to a hidden form from another class? Quote
Administrators PlausiblyDamp Posted November 21, 2014 Administrators Posted November 21, 2014 One way would be to pass the form into the other class when you create it, the other class could have a constructor that takes a parameter of your form. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.