Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Is this possible? How? Please, help.
EDIT: Solved.
Posted
Updated 22-Feb-13 7:12am
v3

You don't. You farm the work out to code running on the UI thread.

You don't touch or manipulate any UI controls created from a thread other that the UI (startup) thread.

Read this[^] for more information.
 
Share this answer
 
Comments
[no name] 22-Feb-13 13:16pm    
Solved)
Dave Kreskowiak 22-Feb-13 14:50pm    
No, you didn't solve it.
Sergey Alexandrovich Kryukov 23-Feb-13 19:32pm    
It's pretty hard to explain, would need a whole article which I'm not going to write. Cross-thread UI call exception is probably blocked, but halabella does not mention it. It's apparently dangerous thing.
—SA
You cannot call anything related to UI from non-UI thread. Instead, you need to use the method Invoke or BeginInvoke of System.Windows.Threading.Dispatcher (for both Forms or WPF) or System.Windows.Forms.Control (Forms only).

You will find detailed explanation of how it works and code samples in my past answers:
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].

See also more references on threading:
How to get a keydown event to operate on a different thread in vb.net[^],
Control events not firing after enable disable + multithreading[^].

—SA
 
Share this answer
 
Comments
[no name] 23-Feb-13 6:52am    
Don't know why you all don't like my solution - it's works perfect with no errors.
Sergey Alexandrovich Kryukov 23-Feb-13 19:30pm    
My references explain how it should be done. Your solution works accidentally, and also you probably have the options which allows to skip cross-thread calls check up.
—SA
Dave Kreskowiak 23-Feb-13 19:50pm    
It APPEARS to work with no errors. There will come a time where it will NOT work.

We've told you, repeatedly, it's a dangerous thing to do and how to do it properly. If you want to ignore that adive and roll that garbage code as "production quality", go right ahead.

Consider yourself warned.
Sergey Alexandrovich Kryukov 23-Feb-13 20:37pm    
Absolutely. "It appears" is apparently not enough. Actually, I always say that working-who-knows-how or just-working is much worse than not working at all, because, giving an illusion of a working solution, it can fail at the worst moment of time.
—SA
[no name] 24-Feb-13 1:53am    
Thanks, I will read..
C#
public void FormLoad{
    Thread tt = new Thread(new ThreadStart(Baloon));
    tt.Start();
}
public void Baloon()
{
    notifyIcon1.BalloonTipTitle = ui_lang[32];
    notifyIcon1.BalloonTipText = ui_lang[33];
    notifyIcon1.ShowBalloonTip(7000);
}

It works!
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 22-Feb-13 14:07pm    
I don't trust you. It should not work.
I don't believe you tried it by yourself. In all cases, this is wrong.
—SA
Dave Kreskowiak 22-Feb-13 14:50pm    
WRONG! It APPEARS to work on YOUR machine. THe problem will come when you get all kinds of little errors, like the ballon not showing up consistently or doesn't paint correctly or you can't dismiss it that you'll sit there and scratch your head all day because you just can't figure out why it suddenly doesnt work.

You NEVER NEVER NEVER NEVER NEVER do ANYTHING involving User Interface controls and painting from a background thread! If you read the article I linked to, you know this and know why it's a bad idea.
Sergey Alexandrovich Kryukov 22-Feb-13 16:32pm    
Exactly. I provided a real answer: usage of UI thread invocation, please see.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900