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. Threading problem

Threading problem

Scheduled Pinned Locked Moved C#
helpquestion
4 Posts 4 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.
  • R Offline
    R Offline
    Rick van Woudenberg
    wrote on last edited by
    #1

    Dear all, I've written a method which I call from a thread. The problem is that it opens the form in the method, as it is suppose to, but it closes the form immediately after it opened it. Any hints ? here's the code : void ultraGrid1_ClickCellButton(object sender, CellEventArgs e) { Thread thread = new Thread(OpenMethod); thread.Name = "something"; thread.Start(); //thread.Join(); } private void OpenMethod() { if (_form == null) { _form = new NewForm(); _form.Closed += new EventHandler(_form_Closed); } _form.WindowState = FormWindowState.Normal; // bring it from the taskbar if necessary _form.Show(); } Kind regards,

    L S 2 Replies Last reply
    0
    • R Rick van Woudenberg

      Dear all, I've written a method which I call from a thread. The problem is that it opens the form in the method, as it is suppose to, but it closes the form immediately after it opened it. Any hints ? here's the code : void ultraGrid1_ClickCellButton(object sender, CellEventArgs e) { Thread thread = new Thread(OpenMethod); thread.Name = "something"; thread.Start(); //thread.Join(); } private void OpenMethod() { if (_form == null) { _form = new NewForm(); _form.Closed += new EventHandler(_form_Closed); } _form.WindowState = FormWindowState.Normal; // bring it from the taskbar if necessary _form.Show(); } Kind regards,

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

      You calling a UI method on a non-UI thread, look at the Output console. An exception should be waiting for you.

      xacc.ide - now with IronScheme support
      IronScheme - 1.0 alpha 2 out now

      S 1 Reply Last reply
      0
      • L leppie

        You calling a UI method on a non-UI thread, look at the Output console. An exception should be waiting for you.

        xacc.ide - now with IronScheme support
        IronScheme - 1.0 alpha 2 out now

        S Offline
        S Offline
        SeeBees
        wrote on last edited by
        #3

        Is it such that everything related to UI-rendering should be done in UI thread?

        1 Reply Last reply
        0
        • R Rick van Woudenberg

          Dear all, I've written a method which I call from a thread. The problem is that it opens the form in the method, as it is suppose to, but it closes the form immediately after it opened it. Any hints ? here's the code : void ultraGrid1_ClickCellButton(object sender, CellEventArgs e) { Thread thread = new Thread(OpenMethod); thread.Name = "something"; thread.Start(); //thread.Join(); } private void OpenMethod() { if (_form == null) { _form = new NewForm(); _form.Closed += new EventHandler(_form_Closed); } _form.WindowState = FormWindowState.Normal; // bring it from the taskbar if necessary _form.Show(); } Kind regards,

          S Offline
          S Offline
          S Senthil Kumar
          wrote on last edited by
          #4

          Calling Show requires that the thread be running a message pump (like Application.Run). Replace _form.Show with _form.ShowDialog and it should work fine - ShowDialog is modal and runs its own message pump.

          Regards Senthil [MVP - Visual C#] _____________________________ My Blog | My Articles | My Flickr | WinMacro

          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