473,378 Members | 1,631 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Strange behaviour ...

My code:

public class aaa
{
public void ShowWelcomeWindow()
{
Form welcome = new Form();
try
{
welcome.ShowDialog();
}
catch(ThreadAbortException)
{
// No exception ...
}
finally
{
welcome.Dispose();
}
}
}

Now:

aaa a = new aaa();
ThreadStart tH = new ThreadStart(a.ShowWelcomeWindow);
Thread t = new Thread(tH);
t.Start();

while(t.ThreadState != ThreadStates.Running)
{
Thread.Sleep(100);
}

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?
Nov 15 '05 #1
2 925
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
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Jacek Jurkowski" <jj********@op.pl> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
My code:

public class aaa
{
public void ShowWelcomeWindow()
{
Form welcome = new Form();
try
{
welcome.ShowDialog();
}
catch(ThreadAbortException)
{
// No exception ...
}
finally
{
welcome.Dispose();
}
}
}

Now:

aaa a = new aaa();
ThreadStart tH = new ThreadStart(a.ShowWelcomeWindow);
Thread t = new Thread(tH);
t.Start();

while(t.ThreadState != ThreadStates.Running)
{
Thread.Sleep(100);
}

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?


Nov 15 '05 #2
I really need that in 3 situations.
1) Process viewer for my application must work on separate thread.
2) Windows service having NotyficationIcon. 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.
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.


Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Paul Drummond | last post by:
Hi all, I am developing software for Linux Redhat9 and I have noticed some very strange behaviour when throwing exceptions within a shared library. All our exceptions are derived from...
3
by: Sebastian C. | last post by:
Hello everybody Since I upgraded my Office XP Professional to SP3 I got strange behaviour. Pieces of code which works for 3 years now are suddenly stop to work properly. I have Office XP...
6
by: Edd Dawson | last post by:
Hi. I have a strange problem involving the passing of command line arguments to a C program I'm writing. I tried posting this in comp.programming yesterday but someone kindly suggested that I'd...
8
by: Dox33 | last post by:
I ran into a very strange behaviour of raw_input(). I hope somebody can tell me how to fix this. (Or is this a problem in the python source?) I will explain the problem by using 3 examples....
20
by: Pilcrow | last post by:
This behavior seems very strange to me, but I imagine that someone will be able to 'explain' it in terms of the famous C standard. -------------------- code -----------------------------------...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.