Delegate and Threading


Author
Message
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
This is a topic that we cover in depth in the training class.  There is a lot of detail that surrounds threading, events, and delegates.  As for your question, you basically understand it.  You would have to create a unique background worker thread for each threaded method that you wanted to call.  Using the ThreadManager, you can fire off as many threads as you need through a single control while managing the events associated with the ThreadManager in a thread-safe manner.
Randy Jean
Randy Jean
StrataFrame User (169 reputation)StrataFrame User (169 reputation)StrataFrame User (169 reputation)StrataFrame User (169 reputation)StrataFrame User (169 reputation)StrataFrame User (169 reputation)StrataFrame User (169 reputation)StrataFrame User (169 reputation)StrataFrame User (169 reputation)
Group: StrataFrame Users
Posts: 105, Visits: 641
What are the pros/cons of using threadmanager vs. backgroundworker? Been reading up on the bgw control and seems to do a lot of what the threadmanager does but allows passing an object through RunAsync and also seems to allow updating user interface controls. The downside I see is that if I want multiple bgw I need to drop several of these on my form where with threadmanager I can just add another thread through AddProcess. New to this world of multi-threading so forgive my ignorance...
StrataFrame Team
S
StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
I didn't realize that the ThreadManager had its own delegates... thought it used ThreadStart and ParameterizedThreadStart, but looks like it doesn't...

So, since you can't pass a parameter, looks like your best bet is going to be to store off that value within a shared variable somewhere and then access it from the other thread.  Don't forget to use a SyncLock if you end up accessing that variable from more than one thread at the same time Wink

Scott Hershberger
Scott Hershberger
StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)
Group: Forum Members
Posts: 10, Visits: 26
Sorry...messed that code up a little ignore the delegate totally. It's just a normal sub with an integer param
Scott Hershberger
Scott Hershberger
StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)StrataFrame Beginner (10 reputation)
Group: Forum Members
Posts: 10, Visits: 26
I need to pass a delegate with a parameter to the thread manager, however, the threadmanager does not take a pure delegate and requires MicroFour.StrataFrame.Threading.ThreadManager.Delegate_ExecutionMethod which does not allow parameters. Is there anyway to get around this?





Public Delegate Sub GetData(ByVal passedInt As Integer)

Dim myMethod As MicroFour.StrataFrame.Threading.ThreadManager.Delegate_ExecutionMethod

myMethod = AddressOf GetDataSub



This obviously does not work since :



Method 'Public Sub GetDataSub(passedInt As Integer)' does not have the same signature as delegate 'Delegate Sub Delegate_ExecutionMethod()'

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search