Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Cross threading in class library

Cross threading in class library

Scheduled Pinned Locked Moved C#
helptutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MAP Tiger
    wrote on last edited by
    #1

    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

    J 1 Reply Last reply
    0
    • M 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 Tiger

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      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

      M 1 Reply Last reply
      0
      • J Judah Gabriel 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

        M Offline
        M Offline
        MAP Tiger
        wrote on last edited by
        #3

        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 and ChangeText procedure do the work needed with SongName 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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups