473,382 Members | 1,423 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,382 software developers and data experts.

Threaded Cross-Class Winform Manipulation

i
Hi,

I'm trying to get a seperate class, initialized by a form class, to
manipulate certain objects on the form (ex: add to a listbox). The
manipulation will occur via a thread that is not the normal WinForm GUI
thread. How would I go about doing this?

I have this code for cross-thread WinForm manipulation, but only from within
the WinForm class:

public delegate void LogDelegate(string txt);

public void Log(string txt)
{
if (InvokeRequired)
{
Invoke(new LogDelegate(Log), txt);
return;
}

lstLog.Items.Insert(0, DateTime.Now.ToString("T") + " - " + txt);
}

Thanks,
Ian
Nov 17 '05 #1
1 2057
i <ty****@gmail.com> wrote:
I'm trying to get a seperate class, initialized by a form class, to
manipulate certain objects on the form (ex: add to a listbox). The
manipulation will occur via a thread that is not the normal WinForm GUI
thread. How would I go about doing this?

I have this code for cross-thread WinForm manipulation, but only from within
the WinForm class:

public delegate void LogDelegate(string txt);

public void Log(string txt)
{
if (InvokeRequired)
{
Invoke(new LogDelegate(Log), txt);
return;
}

lstLog.Items.Insert(0, DateTime.Now.ToString("T") + " - " + txt);
}


You'd do it in exactly the same way as the above, but using form.Invoke
and form.ListLog or however you want to expose the ListBox to other
classes. Of course, you could make sure that the only thing which has
access to the controls is the form class itself, and just give
thread-safe ways of performing certain operations (as you have above).
Personally, I think that's generally preferable to letting other
objects manipulate the UI, but it depends on the situation.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2

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

Similar topics

1
by: Bart Nessux | last post by:
When testing scripts, I normally type 'ctrl' combined with the key 'c' to abort the script, however, this doesn't work with scripts that are threaded. What's the proper way to abort a threaded...
0
by: Ganbold | last post by:
Hi, I'm new to multi-threaded programming and reading the book "Programming with POSIX Threads" and trying to understand concepts and coding. What I'm trying to do is to rewrite mysql client...
2
by: Michal Przytulski | last post by:
Hi, I'm looking information abouth runing PHP CLI application in multi-threaded - on http://www.php.net/manual/pl/ref.pcntl.php i found information abouth process control - but is PHP support...
2
by: Chris | last post by:
I think I already know that the answer is that this can't be done, but I'll ask anyways. Suppose you want to use an RDBMS to store messages for a threaded message forum like usenet and then...
9
by: Randy | last post by:
Hello, I'm having a strange problem. I've got a .NET web app which uses Session variables. Sometime, not all the time, they get cross threaded...that is...one user will have another user's Session...
1
by: Mullin Yu | last post by:
As subject. I have lots of VB6 dll and ocx files and they are single-threaded as VB6 doesn't support multi-threaded indeed. Can I wrap anything at .NET so that multi-threaded feature can be...
6
by: ben | last post by:
I am needing a web service to be single threaded. Is this possible? Any ideas would be helpful
4
by: Redgum | last post by:
I have a windows forms project that uses multiple tabs. On the first tab I have a rich text box that I'd like to be able to post text results from various operational threads - such as "Starting...
5
by: Nasif | last post by:
Hello all, Currently we are developing a multi threaded application in C on linux platform. For our application we have designed a wrapper on pthread library. Now I need some free testing...
14
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
As far as I know, the C Standard has no mention of multi-threaded programming; it has no mention of how to achieve multi-threaded programming, nor does it mention whether the language or its...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.