Delegates
-
I am using BeginInvoke on a delegate to start a Sub. What will happen if I do not call EndInvoke on that delegate? I do not particularly need to monitor it or need to know if it is finished. I tried using threading but did not get it to work. Still trying though.
-
I am using BeginInvoke on a delegate to start a Sub. What will happen if I do not call EndInvoke on that delegate? I do not particularly need to monitor it or need to know if it is finished. I tried using threading but did not get it to work. Still trying though.
You might want to read Asynchronous Method Execution Using Delegates[^] on MSDN.
Invoke
and launching background threads are not 100% interchangable. Wheather one is better than the other depends on what you want to be done in the background. Sooo... What are you doing on the background thread? Are you having any problems with BeginInvoke/EndInvoke? What were the problems you had with threading? RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome -
You might want to read Asynchronous Method Execution Using Delegates[^] on MSDN.
Invoke
and launching background threads are not 100% interchangable. Wheather one is better than the other depends on what you want to be done in the background. Sooo... What are you doing on the background thread? Are you having any problems with BeginInvoke/EndInvoke? What were the problems you had with threading? RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming GnomeI'm checking for application updates on the background thread. My application does this once per day similar to Windows Automatic Updates. The problem I had with threading is that I was not able to pass arguments to the procedure I was calling. However, I've figured a way to work around that by making the arguments available to the procedure (thru a config file it reads). The question I had with BeginInvoke is what would happen if I do not call EndInvoke on that delegate? Will it just exit after it has done it's work. What would happen if the delegate i've invoked goes out of scope but the method invoked is not finished? Will the method being invoked keep working until it finishes? Or will it just exit or worse?
-
I'm checking for application updates on the background thread. My application does this once per day similar to Windows Automatic Updates. The problem I had with threading is that I was not able to pass arguments to the procedure I was calling. However, I've figured a way to work around that by making the arguments available to the procedure (thru a config file it reads). The question I had with BeginInvoke is what would happen if I do not call EndInvoke on that delegate? Will it just exit after it has done it's work. What would happen if the delegate i've invoked goes out of scope but the method invoked is not finished? Will the method being invoked keep working until it finishes? Or will it just exit or worse?
This is something that's usually done by a seperate app, not a component. The application usually launches the update app which goes off on it's own and checks for updates and downloads them. Some communication with the parent app is possible through Remoting. If the user requests that the update be installed now, it tells the updater to do so and quits. The updater continues on and installs the updates, then could optionally relaunch the new version of the parent app. BeginInvoke returns an IAsyncResult object, that can be ignored without any consequences. You don't have to do anything with it or dispose it. You also don't have to call EndInvoke, unless you want any return values from your method call. The delegate you invoke won't go out of scope until it's done executing. Remember its on its own thread and executing completely independent of the thread that called it. It will keep running until it runs out of code to execute or fails and throws an unhandled exception. The problem with an exception is you won't know it happened on your main thread because exceptions don't cross thread boundries, unless you call EndInvoke. Any exception that was thrown on the background thread will finally be re-thrown on your main thread only upon calling EndInvoke. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome