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

Is there a way to invoke a method in another thread form current thread?

May be it's not obvious what am i asking for...
I have 2 threads in my application.
The first thread responds for the user interface and sending key
combinations,
the second thread listening keyboard messages from keyboard hook. There is a
report in interface, and i need to send incoming key combinations to it.
But adding items in visual report is not appropriate by the second (hook)
thread.

I know, i can use asynchronous delegate to send message to report, but in
that case this will be done by thread that is not equals interface thread.
Can i just call report method, but in interface thread?

But i need it not only in forms... There is a queue, the hook thread is
enqueuing messages to it. And i need to ask a second thread process it. How
can i do this?

Aug 25 '05 #1
6 5508
If both threads are running in the same process then you can simply use
a synchronised queue object that are both accessible by both thread
(that if you want to use queue).

Victor Hadianto
http://www.hadianto.net/destination

Aug 25 '05 #2
> If both threads are running in the same process then you can simply use
a synchronised queue object that are both accessible by both thread
(that if you want to use queue).


But how can i inform another thread that there is new data queue?

I know, i can use timer in another thread, but is very bad. I need very fast
reaction, and i don't want to overload cpu with timer with 1 millisecond
interval.

By the way, both thread is running through Application.Run() (in
windows message loop).
Aug 25 '05 #3
You can try the following:

a) Poll the queue

b) Sleep the thread A and wake the thread A when thread B insert an
object in the queue. You can use the Monitor object to achieve this.

c) Have a look ThreadPool.QueueUserWorkItem(); That maybe enough for
what you're trying to achieve.

Victor Hadianto
http://www.hadianto.net/destin ation

Aug 26 '05 #4
> a) Poll the queue

b) Sleep the thread A and wake the thread A when thread B insert an
object in the queue. You can use the Monitor object to achieve this.

c) Have a look ThreadPool.QueueUserWorkItem(); That maybe enough for
what you're trying to achieve.


This is not acceptable.
Both thread must be alive.

Listening thread have a hook registered in it.
Interface thread is displaying user interface.

Both of them in window message loop, after registering hook in first thread
i just run Application.Run(). After preparations in second thread i also run
Application.Run(). Method Application.Run() never returns until
Application.Exit() method called.

I need a mechanism such as for example hook do, i have registered callback
function to system, and the system callback to my thread (this function is
not performed by the some system thread). And i need something like this.
Just call a function in second thread from first, when the first thread will
be in some fit state for it.
Aug 26 '05 #5
> You can try the following:

a) Poll the queue

b) Sleep the thread A and wake the thread A when thread B insert an
object in the queue. You can use the Monitor object to achieve this.

c) Have a look ThreadPool.QueueUserWorkItem(); That maybe enough for
what you're trying to achieve.


And i can't use thread pool because i must run code that can show some form
for
example. So i must run it from thread that's have a window message loop and
runs forever when application is running - for example my second thread.
Aug 26 '05 #6
Vladimir,

If you can get a reference to one of the application's forms in the
second thread then you can use the BeginInvoke or Invoke from that form
to marshal the execution of a delegate onto the thread hosting that
form.

Brian

Vladimir wrote:
May be it's not obvious what am i asking for...
I have 2 threads in my application.
The first thread responds for the user interface and sending key
combinations,
the second thread listening keyboard messages from keyboard hook. There is a
report in interface, and i need to send incoming key combinations to it.
But adding items in visual report is not appropriate by the second (hook)
thread.

I know, i can use asynchronous delegate to send message to report, but in
that case this will be done by thread that is not equals interface thread.
Can i just call report method, but in interface thread?

But i need it not only in forms... There is a queue, the hook thread is
enqueuing messages to it. And i need to ask a second thread process it. How
can i do this?


Aug 26 '05 #7

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

Similar topics

2
by: Tom | last post by:
Hi Everybod I want to update some controls in a form from another threads. I did it by passing the form to that thread and calling a delegate with Form1.Invoke, I want to have just one delegeate...
5
by: RickDee | last post by:
Please help, anybody. I am trying to write a program so that it can launch an exe file ( which is also genereated in C# ) and then simulate the button clicking and invoke the methods inside the...
4
by: Altramagnus | last post by:
I have a form first created my the main thread. I have another thread monitoring the IO. Upon receiving certain message, I want to show/unhide the form. When the form is first created ( handle...
0
by: Pawan Narula via DotNetMonster.com | last post by:
hi all, i'm using VB.NET and trying to code for contact management in a tree. all my contacts r saved in a text file and my C dll reads them one by one and sends to VB callback in a sync mode...
6
by: Vladimir | last post by:
May be it's not obvious what am i asking for... I have 2 threads in my application. The first thread responds for the user interface and sending key combinations, the second thread listening...
4
by: Chris Dunaway | last post by:
I have a main form with a "lock" button. When the lock button is clicked, another form is shown using ShowDialog(this). The user must enter their PIN on this form to close it and resume the main...
6
by: k.mellor | last post by:
Hi, I hope someone can help. I have written a simple form to demonstrate my problem/question. The code follows. The form starts a thread, which using delegates updates a label (Every second...
1
by: SAL | last post by:
Hello, I'm developing this remoting app (.net 2.0) and I need to bring the server app's form to the front often. Since you can not do cross-thread communication on a form or control without using...
0
by: Sebouh | last post by:
Hi guys. I was messing with Threading and stuff, and i have reached a point where i'm not sure what's causing the current behavior. Here's the code: Public Class Form1 Private Sub...
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?
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
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...
0
tracyyun
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...
0
agi2029
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,...
0
isladogs
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...
0
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...

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.