Hi,
I have big problem. I made generic form which can be rendered, and as a
result of that action, I get System.Windows. Forms.Form object.
Rendering must be done in GUI thread (one which has message pump), but I
can't garantee that the using of Render function will be made in GUI thread.
This is Render function:
public object Render(Synchron izer.T sync)
{
return sync.Render(thi s); <-- this function is making real Form
}
I want that Render function is doing in GUI thread allways. Can anyone
help me?
Thanx, Cheya 11 4253
Hello Cheya,
You should look into the InvokeRequired property. http://msdn.microsoft.com/library/de...uiredtopic.asp
A basic example:
<pseudo-code>
public delegate void TestMeDelegate( );
public void TestMe()
{
if(!this.Invoke Required)
{
//update ui elements as needed...
}
else
{
TestMeDelegate delegate = new TestMeDelegate( );
this.BeginInvok e(delegate);
}
}
</pseudo-code>
Also, here is a great article on Multi-threading WinForms apps. http://msdn.microsoft.com/library/de...ms06112002.asp
HTH,
Kyril
"Nenad Dobrilovic" <ch*******@hotm ail.com> wrote in message
news:u5******** ******@TK2MSFTN GP10.phx.gbl... Hi, I have big problem. I made generic form which can be rendered, and as a result of that action, I get System.Windows. Forms.Form object. Rendering must be done in GUI thread (one which has message pump), but I can't garantee that the using of Render function will be made in GUI thread. This is Render function:
public object Render(Synchron izer.T sync) { return sync.Render(thi s); <-- this function is making real Form }
I want that Render function is doing in GUI thread allways. Can anyone help me? Thanx, Cheya
Kyril Magnos wrote: Hello Cheya,
You should look into the InvokeRequired property. http://msdn.microsoft.com/library/de...uiredtopic.asp
A basic example: <pseudo-code> public delegate void TestMeDelegate( ); public void TestMe() { if(!this.Invoke Required) { //update ui elements as needed... } else { TestMeDelegate delegate = new TestMeDelegate( ); this.BeginInvok e(delegate); } } </pseudo-code>
Also, here is a great article on Multi-threading WinForms apps. http://msdn.microsoft.com/library/de...ms06112002.asp
HTH,
Kyril
"Nenad Dobrilovic" <ch*******@hotm ail.com> wrote in message news:u5******** ******@TK2MSFTN GP10.phx.gbl...
Hi, I have big problem. I made generic form which can be rendered, and as a result of that action, I get System.Windows. Forms.Form object. Rendering must be done in GUI thread (one which has message pump), but I can't garantee that the using of Render function will be made in GUI thread. This is Render function:
public object Render(Synchron izer.T sync) { return sync.Render(thi s); <-- this function is making real Form }
I want that Render function is doing in GUI thread allways. Can anyone help me? Thanx, Cheya
The problem is that InvokeRequired property, Invoke() method, etc. is
defined in System.Windows. Forms.Control class.
But, my class is generic form (it is not inherited from
System.Windows. Forms.Control), which can be 'rendered' using Render()
method and Synchronize object.
I want to tell GUI thread 'do this to me' from my object.
Nenad Dobrilovic <ch*******@hotm ail.com> wrote: The problem is that InvokeRequired property, Invoke() method, etc. is defined in System.Windows. Forms.Control class. But, my class is generic form (it is not inherited from System.Windows. Forms.Control), which can be 'rendered' using Render() method and Synchronize object. I want to tell GUI thread 'do this to me' from my object.
Then you'll need to know *a* control (any control) which is running on
that thread. Bear in mind that there can in fact be several GUI threads
- however many you call Application.Run on, basically. (Or however many
you create controls in, depending on your view of things.)
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jon Skeet [C# MVP] wrote: Nenad Dobrilovic <ch*******@hotm ail.com> wrote:
The problem is that InvokeRequired property, Invoke() method, etc. is defined in System.Windows. Forms.Control class. But, my class is generic form (it is not inherited from System.Window s.Forms.Control ), which can be 'rendered' using Render() method and Synchronize object. I want to tell GUI thread 'do this to me' from my object.
Then you'll need to know *a* control (any control) which is running on that thread. Bear in mind that there can in fact be several GUI threads - however many you call Application.Run on, basically. (Or however many you create controls in, depending on your view of things.)
That means that GUI thread can be any thread - if I create control in
that thread? Or, I must call Application.Run on that thread to become
GUI thread?
Nenad Dobrilovic <ch*******@hotm ail.com> wrote: That means that GUI thread can be any thread - if I create control in that thread? Or, I must call Application.Run on that thread to become GUI thread?
You should use Application.Run to run a message pump in a given thread.
However, you should only access a control from the thread which created
it.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jon Skeet [C# MVP] wrote: Nenad Dobrilovic <ch*******@hotm ail.com> wrote:
That means that GUI thread can be any thread - if I create control in that thread? Or, I must call Application.Run on that thread to become GUI thread?
You should use Application.Run to run a message pump in a given thread. However, you should only access a control from the thread which created it.
OK, I understend that one thread must have message pump - lets call it
'GUI thread'.
Does controle can be created and accesed in a thread other than GUI
thread? How it receives messages from message pump in that case? Does
entire form must be created in that thread also?
Nenad Dobrilovic <ch*******@hotm ail.com> wrote: OK, I understend that one thread must have message pump - lets call it 'GUI thread'.
No, *at least* one thread must have a message pump if you want to use a
GUI.
Does controle can be created and accesed in a thread other than GUI thread? How it receives messages from message pump in that case? Does entire form must be created in that thread also?
I don't know whether you can create a form in one thread and create its
child controls in another, then run a message pump on both threads -
but it sounds like a hideously bad idea to me, and one which will
*probably* break.
You can, however, run two different forms in two different threads.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jon Skeet [C# MVP] wrote:
I'm sorry to bother you, but I have more questions :) You can, however, run two different forms in two different threads.
And each one *must* have it's own message pump? Or one message pump is
enought?
Is there any way to start message pump other than Application.Run ()?
Thank you
Nenad Dobrilovic <ch*******@hotm ail.com> wrote: I'm sorry to bother you, but I have more questions :)
Sure, no problem. You can, however, run two different forms in two different threads. And each one *must* have it's own message pump? Or one message pump is enought?
I believe there's a message pump per thread. I'm not an expert on the
Win32 side of things, to be honest, but I can't see how you could
easily share a message pump between different threads if each message
has to go to a specific thread.
Is there any way to start message pump other than Application.Run ()?
I believe showing a modal dialog will run a message pump for the
duration of the dialog's visibility, but other than that, I don't know
of any way of using the built-in one. You could use P/Invoke to call
the Win32 functions yourself, of course - but why do you want to avoid
calling Application.Run ?
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: adeger |
last post by:
Having trouble with my first forays into threads. Basically, the
threads don't seem to be working in parallel (or you might say are
blocking). I've boiled my problems to the following short code block
and ensuing output. Seems like the output should be all interleaved
and of course it's not. Running Python 2.2 from ActiveState on
Windows XP (also doesn't work on Windows 2000).
Thanks in advance!
adeger
|
by: Gilles Leblanc |
last post by:
Hi I have started a small project with PyOpenGL. I am wondering what
are the options for a GUI. So far I checked PyUI but it has some
problems with 3d rendering outside the Windows platform.
I know of WxPython but I don't know if I can create a WxPython window,
use gl rendering code in it and then put widgets on top of that...
|
by: Ivan |
last post by:
Hi
I have following problem: I'm creating two threads who are performing some
tasks. When one thread finished I would like to restart her again (e.g. new
job). Following example demonstrates that. Problem is that when program is
started many threads are created (see output section), when only two should
be running at any time. Can you please help me to identify me where the
problem is?
Best regards
|
by: Matthew Groch |
last post by:
Hi all,
I've got a server that handles a relatively high number of concurrent
transactions (on the magnitude of 1000's per second). Client
applications establish socket connections with the server. Data is
sent and received over these connections using the asynchronous model.
The server is currently in beta testing. Sporadically over the course
of the day, I'll observe the thread count on the process (via perfmon)
start climbing....
|
by: Razzie |
last post by:
Hi all,
A question from someone on a website got me thinking about this, and I
wondered if anyone could explain this.
A System.Threading.Timer object is garbage collected if it has no references
to it. But what about threads? If I start a new thread that only does 1+1,
is it garbage collected after that? If so, do all threads get garbage
collected eventually that are 'done'? And if not, why not? Are there
references to the thread that...
| |
by: droopytoon |
last post by:
Hi,
I start a new thread (previous one was "thread timing") because I have
isolated my problem.
It has nothing to do with calling unmanaged C++ code (I removed it in a
test application).
I have a thread "_itTaskThread" running.
The application is listening on a TCP port.
It accepts 2 connection from a client.
I simulate a crash on the client side (using "Debug->StopDebugging").
|
by: mareal |
last post by:
I have noticed how the thread I created just stops running. I have added
several exceptions to the thread
System.Threading.SynchronizationLockException
System.Threading.ThreadAbortException
System.Threading.ThreadInterruptedException
System.Threading.ThreadStateException
to see if I could get more information about why the thread stops running
but that code is never executed. Any ideas on how I can debug this?
|
by: Bob Day |
last post by:
Using vs2003, vb.net
I start a thread, giving it a name before start. Code snippet:
'give each thread a unique name (for later identification)
Trunk_Thread.Name = "Trunk_0_Thread"
' allow only 1 thread per line
Trunk_Thread.ApartmentState = ApartmentState.STA
|
by: Charles Law |
last post by:
My first thought was to call
WorkerThread.Suspend
but the help cautions against this (for good reason) because the caller has
no control over where the thread actually stops, and it might have a lock
pending, for example.
I want to be able to stop a thread temporarily, and then optionally resume
it or stop it for good.
|
by: John Nagle |
last post by:
There's no way to set thread priorities within Python, is there?
We have some threads that go compute-bound, and would like to
reduce their priority slightly so the other operations, like
accessing the database and servicing queries, aren't slowed
as much.
John Nagle
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |