Strange behaviour ...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jacek Jurkowski

    Strange behaviour ...

    My code:

    public class aaa
    {
    public void ShowWelcomeWind ow()
    {
    Form welcome = new Form();
    try
    {
    welcome.ShowDia log();
    }
    catch(ThreadAbo rtException)
    {
    // No exception ...
    }
    finally
    {
    welcome.Dispose ();
    }
    }
    }

    Now:

    aaa a = new aaa();
    ThreadStart tH = new ThreadStart(a.S howWelcomeWindo w);
    Thread t = new Thread(tH);
    t.Start();

    while(t.ThreadS tate != ThreadStates.Ru nning)
    {
    Thread.Sleep(10 0);
    }

    t.Abort();
    t.Join();

    Why after running this code window showed by aaa class
    some times releases immediately and some times it waits for
    user action such a mouse move before releases?


  • Dmitriy Lapshin [C# / .NET MVP]

    #2
    Re: Strange behaviour ...

    Hi Jacek,

    I should say your approach is wrong by design. All UI should be handled
    within a single thread, and you should only delegate non-UI tasks to
    additional threads.

    --
    Dmitriy Lapshin [C# / .NET MVP]
    X-Unity Test Studio

    Bring the power of unit testing to VS .NET IDE

    "Jacek Jurkowski" <jjurkowski@op. pl> wrote in message
    news:%234bRqo3o DHA.2012@TK2MSF TNGP12.phx.gbl. ..[color=blue]
    > My code:
    >
    > public class aaa
    > {
    > public void ShowWelcomeWind ow()
    > {
    > Form welcome = new Form();
    > try
    > {
    > welcome.ShowDia log();
    > }
    > catch(ThreadAbo rtException)
    > {
    > // No exception ...
    > }
    > finally
    > {
    > welcome.Dispose ();
    > }
    > }
    > }
    >
    > Now:
    >
    > aaa a = new aaa();
    > ThreadStart tH = new ThreadStart(a.S howWelcomeWindo w);
    > Thread t = new Thread(tH);
    > t.Start();
    >
    > while(t.ThreadS tate != ThreadStates.Ru nning)
    > {
    > Thread.Sleep(10 0);
    > }
    >
    > t.Abort();
    > t.Join();
    >
    > Why after running this code window showed by aaa class
    > some times releases immediately and some times it waits for
    > user action such a mouse move before releases?
    >
    >[/color]

    Comment

    • Jacek Jurkowski

      #3
      Re: Strange behaviour ...

      I really need that in 3 situations.
      1) Process viewer for my application must work on separate thread.
      2) Windows service having NotyficationIco n. Notyfication Icon doesn't
      work just added to service component - it must be run on a separate
      modal window what practically means a start of a new thread because
      other case ShowDialog of that form prevents service from starting.
      3) Welcome window displaying what's happening.

      I Solved problem making static event and method that releases window
      from itself where main thread requests it.
      [color=blue]
      > I should say your approach is wrong by design. All UI should be handled
      > within a single thread, and you should only delegate non-UI tasks to
      > additional threads.[/color]



      Comment

      Working...