Click here to Skip to main content
13,288,520 members (65,229 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Is this possible? How? Please, help.
EDIT: Solved.
Posted 22-Feb-13 7:59am
Updated 22-Feb-13 8:12am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
halabella 22-Feb-13 13:16pm
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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

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[^],
Control events not firing after enable disable + multithreading[^].

halabella 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.
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.
halabella 24-Feb-13 1:53am
Thanks, I will read..
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

public void FormLoad{
    Thread tt = new Thread(new ThreadStart(Baloon));
public void Baloon()
    notifyIcon1.BalloonTipTitle = ui_lang[32];
    notifyIcon1.BalloonTipText = ui_lang[33];

It works!
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.
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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.171207.1 | Last Updated 22 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100