Cross threading in class library
-
Hi I am working with iTunes library. I am supposed to implement it into a class library. The problem is that to respond to events associated to iTunesApp I had to disable
CheckForIllegalCrossThreadCalls
but however in class library, this property isnt supported. Now, I am stuck in between and not able to figure out the solution. Please help me that how to enable Cross thread operations or how to call the event safely without compromising cross thread restriction. I would be very thankful for your kind response. Thanks MAP Tiger -
Hi I am working with iTunes library. I am supposed to implement it into a class library. The problem is that to respond to events associated to iTunesApp I had to disable
CheckForIllegalCrossThreadCalls
but however in class library, this property isnt supported. Now, I am stuck in between and not able to figure out the solution. Please help me that how to enable Cross thread operations or how to call the event safely without compromising cross thread restriction. I would be very thankful for your kind response. Thanks MAP TigerWhen a function is called on a background thread, just post to the synchronization context:
void SomeFunctionOnABackgroundThread()
{
SynchronizationContext.Current.Post(DoSomethingOnCorrectThread, "hello");
}void DoSomethingOnCorrectThread(object state)
{
Console.WriteLine(state); // prints "hello"
}The above code works for both WPF and WinForms.
Tech, life, family, faith: Give me a visit. The apostle Paul, modernly speaking: Epistles of Paul Judah Himango
-
When a function is called on a background thread, just post to the synchronization context:
void SomeFunctionOnABackgroundThread()
{
SynchronizationContext.Current.Post(DoSomethingOnCorrectThread, "hello");
}void DoSomethingOnCorrectThread(object state)
{
Console.WriteLine(state); // prints "hello"
}The above code works for both WPF and WinForms.
Tech, life, family, faith: Give me a visit. The apostle Paul, modernly speaking: Epistles of Paul Judah Himango
Hi Thanks for the reply. I actually needed it in class library which will be basically hosted as a BHO to IE. Moreover, I have solved the problem and mentioning that here so may be useful for any other person.
SongName = "Artist: " + myTrack.Artist + " - Name: " + myTrack.Name; Thread myThread = new Thread(ChangeText); myThread.Start();
SongName
is defined on class level andChangeText
procedure do the work needed withSongName
Now the other question needs attention which is about invoking javascript function if someone can do help. Regards,MAP Tiger Tiger Softwares Software Designer and Developer VB.NET, ASP.NET, VFP