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. Unmanaged thread in C#

Unmanaged thread in C#

Scheduled Pinned Locked Moved C#
csharpc++data-structureshelpquestion
2 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.
  • _ Offline
    _ Offline
    __DanC__
    wrote on last edited by
    #1

    I'm using a DLL written in C++ which creates a processing thread which processes items added to a queue from other threads. This works well from unmanaged code but I am now trying to use the DLL in a managed application. The thread is created and runs as expected processing items passed to it from C#, the problem occurs when I try to call Application.Run(dialog) or dialog.ShowDialog(). The form is destroyed immediately so it simply flashes on the screen and disappears. This does not happen when the unmanaged thread is not running. The loop within the C++ thread is simply:

    while( true )
    {
    WaitForSingleObject(hEvent);
    while( !queue.empty() )
    {
    DoProcess(queue.front());
    }
    }

    And the thread is created with:

    g_hThread = CreateThread(NULL, NULL, ThumbnailThreadProc, NULL, 0, &g_nThreadId);

    Is there a reason for this behaviour?

    L 1 Reply Last reply
    0
    • _ __DanC__

      I'm using a DLL written in C++ which creates a processing thread which processes items added to a queue from other threads. This works well from unmanaged code but I am now trying to use the DLL in a managed application. The thread is created and runs as expected processing items passed to it from C#, the problem occurs when I try to call Application.Run(dialog) or dialog.ShowDialog(). The form is destroyed immediately so it simply flashes on the screen and disappears. This does not happen when the unmanaged thread is not running. The loop within the C++ thread is simply:

      while( true )
      {
      WaitForSingleObject(hEvent);
      while( !queue.empty() )
      {
      DoProcess(queue.front());
      }
      }

      And the thread is created with:

      g_hThread = CreateThread(NULL, NULL, ThumbnailThreadProc, NULL, 0, &g_nThreadId);

      Is there a reason for this behaviour?

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      Two UI threads in 1 app maybe?

      xacc.ide - now with TabsToSpaces support
      IronScheme - 1.0 beta 1 - out now!
      ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))

      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