How to communicate between threads?

Hi, there

I used "AfxBeginThread()" to run a background working thread, while keeping the displaying thread.  Because I got many file names in working thread, I want to show them in the displaying thread.  How to get those CStringArray pointer from working thread?

Thanks

Gary
0
anonymous (74717)
4/13/2004 4:31:07 PM
vc.mfc 33608 articles. 0 followers. Follow

2 Replies
424 Views

Similar Articles

[PageSpeed] 35

On Tue, 13 Apr 2004 09:31:07 -0700, "Gary"
<anonymous@discussions.microsoft.com> wrote:

>Hi, there,
>
>I used "AfxBeginThread()" to run a background working thread, while keeping the displaying thread.  Because I got many file names in working thread, I want to show them in the displaying thread.  How to get those CStringArray pointer from working thread? 

Put them in a shared place (global or member scope) or pass a pointer
to it in using the pParam argument

0
Vincent
4/13/2004 5:11:08 PM
Gary wrote:

> Hi, there,
> 
> I used "AfxBeginThread()" to run a background working thread, while keeping the displaying thread.  Because I got many file names in working thread, I want to show them in the displaying thread.  How to get those CStringArray pointer from working thread? 
> 
> Thanks.
> 
> Gary

The simplest way is to allocate something in the thread (with 'new') and 
pass its address in wParam and/or lParam in a message to the main 
window.  After processing it in the main window 'delete' it.  See
http://www.mvps.org/vcfaq/mfc/12.htm

-- 
Scott McPhillips [VC++ MVP]

0
scottmcp8856 (490)
4/14/2004 3:04:59 AM
Reply:

Similar Artilces:

How to realize communication problem?
Hello everybody. I am working on a project in which I read/write data via rs-232 from/to my Windows application to/from an microcontroller. Now, my boss wants me to write a library which he can use for different microcontrollers. This library should store any changes of data. So the desired microcontroller should just be able to pick up the data. You can think of it this way: Me, representing the Windows application, put a sheet of information into a drawer. A buddy of mine, (representing a microcontroller) can go to the drawer an pick up the sheet for further treatment. So, my quest...

To Thread or not to thread
I am using a CRecordset object to retrieve data from a remote server. The time to retrieve the data is highly variable because of network traffic etc etc etc and has varied from a few ms to almost a minute. Question: Is it a good practice to use a worker thread to handle the database exchange to avoid having my main thread block for long periods of time? I assume that I would let the exchange timeout and then check the return status and a global variable to determine if it should keep trying until it returned data ( might be null but that's ok). Ron H. Ron, While it may be a tin...

Slow or no communication at all
Hello all. Since I'm new around here, please let me know if this is the right place to post this. I've been checking these forums for a long time now, but fortunately I always found what I was looking for and never had the need to post. For that, I want to thank you all for the tremendous work (and help) everyone participating here have been given throughout these years. The problem that brings me here today, relates not entirely to the SBS 2003. What happens is that we have several MAC OS machines connecting to several shares in a SBS 2003. Everything was ok untill one o...

How to communicate between threads?
Hi, there I used "AfxBeginThread()" to run a background working thread, while keeping the displaying thread. Because I got many file names in working thread, I want to show them in the displaying thread. How to get those CStringArray pointer from working thread? Thanks Gary On Tue, 13 Apr 2004 09:31:07 -0700, "Gary" <anonymous@discussions.microsoft.com> wrote: >Hi, there, > >I used "AfxBeginThread()" to run a background working thread, while keeping the displaying thread. Because I got many file names in working thread, I want to show them i...

More about threads
Hi! One computer with two cores running an application that use only the main thread will be given time slice but if this same application use several threads then as I assume will be given more cpu time because of using additional threads. I mean for example if you have three threads then you will be given three time slices. //Tony "Tony Johansson" <johansson.andersson@telia.com> wrote in message news:uHU9x8O8KHA.1760@TK2MSFTNGP04.phx.gbl... > Hi! > > One computer with two cores running an application that use only the main > thread will...

Thread & Exception
Hi All, We have global data structure that is shared across all the threads of the application. Sometime one of the thread causes exception which results in an abrupt behavior with the data structure. Is is possible that the exception may cause corrupting the global data structure such as Semaphore or global data. Regards, Debasish Pramanik Have you done synchronization with the structure? YOu dod not actually give anything other than the vague description "global data structure", which is pretty meaningless when it comes to answering detailed questions about multithreaded acces...

URGENT: Outlook 2003 / Exchange 2003 SP1 communication ports.
Hi, If anyone could help me with this I would be more than grateful. We have moved our Exchange Server to a DMZ with public address space, we are trying to connect Outlook 2003 clients to the server from our private address space. The routing is all set up correctly as we can ping both ways which leads me to believe it's a port problem, i.e. I haven't opened enough up. I've searched TechNet for the relevant documents and have made the needed changes where necessary. I have set a high static port in the registry on the exchange server and our domain controllers for RPC AD re...

How do I find all my old threads in here?
Is there a place where you can see all its previous threads? Hi Rasmus, If you use a newsreader like Windows Mail or Outlook Express, it's a simple matter of clicking on the 'From' column and scrolling down. -- Cheers macropod [Microsoft MVP - Word] "Rasmus" <Rasmus@discussions.microsoft.com> wrote in message news:4ADEF95A-BBE0-4D9F-9290-B46FC88E24C1@microsoft.com... > Is there a place where you can see all its previous threads? Hi, Yes. You can old threads for a limited time period by performing the following steps. 1. If you are...

Communicating
Hello! I am writning a program that will communicate with a server (Linux) using RS232 or TCP/IP. The server is using the same protocol for both. The protocol is rather 'chatty', so for each command there is a lot of sending and receiving. I have created a test program for the RS232 communication using blocking. It works but the program freezes until the communication is done... So I thinking about using some kind of event driven way. I have looked at Mr. Ramon de Klein's serial classes, and they look very good http://www.codeproject.com/system/serial.asp However I need t...

Firewire communication
Hi guys, I am trying to interact with a camera through firewire. I wrote a code based on the example given in MSDN. When I execute the code it always return the value 1 no matter whether the device is connected or disconnected. Please let me know what went wrong, i couldnt figure out the problem so for. My code is as follows. -------------------------------------- void CFireDlg::OnDeviceNotify() { // TODO: Add your control notification handler code here CString cs; bool bDevInterResult=FALSE; HDEVNOTIFY *hdn=NULL; bDevInterResult = DoRegisterDeviceInterface(GUID_MP1394MI,...

when my window talks to my thread
hi, I started my ui thread like this theApp.m_uithread=(CMyUIThread*)AfxBeginThread(RUNTIME_CLASS(CMyUIThread)); and I have a window that talks to it like this CMyWnd::MyFunction() { theApp.m_uithread->PostThreadMessageW( ... ); } but when I lock like this CMyWnd::MyFunction() { theApp.m_uithread->PostThreadMessageW( ... ); m_myCEvent = new CEvent(); m_myCEvent->Lock(); } it gets in a deadlock and the function in my ui thread that I called via theApp.m_uithread->PostThreadMessageW stops running. Is what I am calling a ui thread really a ui thread? Am I doing it right? Is th...

Cross thread messaging
I'm sending a message from a worker thread to a UI thread in the same application using ::PostMessage. Although the sending thread only sends the message once the target window (CListView derived) is receiving the message twice. Using Spy++ only shows the message being sent once. Anybody have any ideas? Thanks -- Coadtoad Not possible. I've never seen this. What is your evidence that it is being received twice? Since Spy++ is showing not the sending of the message, but the receipt of the message, if it only shows one receipt of the message, you are only getting it once (Spy++...

Windows Thread priority
Hello, I tried a quick test on windows threads and have a question about priorities. I made a Dialog app, and a class CMyThread : public CWinThread. I added a ListCtrl to the dialog and then, in the OnIdle function of MyThread, call the function InsertItem of the ListCtrl (using GetDlgItem). When I call ::AfxBeginThread(RUNTIME_CLASS(CMyThread)); it works (the list is quickly populated), but the main dialog doesn't seem to receive any message. The thread seems to take all the process time. When I call ::AfxBeginThread(RUNTIME_CLASS(CMyThread), THREAD_PRIORITY_BELOW_NORMAL); it works fi...

threadpool: how can I make sure just an X amount of threads (CPU's) are used?
Hi, I've made a test project to see how the CPU usage will react based on the example given on: http://msdn.microsoft.com/en-us/library/system.thread= ing.threadpool.queueuserworkitem(VS.71).aspx The code is below. What I want to achieve is to be able to make sure that for a number of task send to the threadpool (or any other solution), I will only use x number of CPU=92s. With the code below, it doesn=92t matter how I set ThreadPool.SetMaxThreads and ThreadPool.SetMinThreads, when I run the program, all my CPU=92s are consumed. I=92ve tested this on a computer with 2 and wit...

Excel communicating to csharp application
In Excel I need some information that the csharp application holds. What would be the best aproach for this problem. Any help is really appreciated. THANKS ...

communication
My client needs to communicate between two computers. Is there anyway they can share calendars without a server. I think I know the answer and its nuts. The work arounds I have tried do not work efficiently. Can someone steer me in the right direction? I need to share calendars and winfax pro files ? Thanks Take a look here, it may help: http://www.slipstick.com/outlook/share.htm --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due to the (insert latest virus name here) virus, all mail sent to my personal account will be deleted without r...

thread #3
how can ia crearte a new Cdialog runing under new thread mido1971 wrote: > how can ia crearte a new Cdialog runing under new thread mido: It is really not a good idea to have GUI components in a secondary thread. Just use a worker thread, or a window-less UI thread. If you have a CDialog-derived class, you can have individual methods run in the secondary thread, but they should only update the GUI using PostMesage() or SendMessage(). David Wilkinson To add to David's advice (good as usual) you can send a message to the UI thread that tells it to pop up the dialog for you wi...

Handling Thread communications
I have 2 threads used for serial communications (receive and transmit). I've wrestled with a couple of issues off and on for long time. 1. I currently use a ring buffer for the receive thread to put data in. When data is received, the thread uses PostMessage() to send a message to the application to process the data. This works for the most part except now I have encountered a problem when I display a MessageBox() while processing received data; I get more messages from the thread that seem to interfere with the process. ie the MessageBox displays twice for some reason. When I chang...

Entourage communication issue
My entourage quit communicating last week. Worked fine wednesday, thursday not. I can open entourage, but it won't send or retrieve mail. times out and gives a message that it's a server issue. My wife's works fine. tried installing the latest upgrade from microsoft, still no change. Both our macs have the same email configuration. tried the fixes given in the help section - snding myself an email, restarting entourage, etc, nothing. I'm not a computer genius, and need help. By the way, if i go into windstream via the internet, every thing's normal Thanks,Tj On 7/24...

Threads
For the longest, for my non-I/O based thread work, I used WaitForMultiObjects (WFMO) as a way to wait for a set of worker threads to complete, simpling by putting the thread handles in an array and passing it to WFMO, for example: // Wait (infinitely) for 10 threads to ALL complete. HANDLE hThreads[10] = {0}; for(int i=0; i<10; i++) { hThreads[i] = CreateThread(.......); } WFMO(hThreads,10,TRUE,INFINITE); I wish to do the same in C#, I can start the threads, but I don't see a simple WFMO() idea. Ideally, I wish to have a ca...

signal about an event from a thread
hi, how can i send a signal about an event from a thread to mfc application. plz help Use PostMessage() to post a message to the appropriate window. Then, set up a handler in the "appropriate window" to do whatever based on the message receieved. You can pass parameters in the message to let the handler know what you're trying to tell it. Tom "dips" <deepikasood30@gmail.com> wrote in message news:1137681136.967473.193080@o13g2000cwo.googlegroups.com... > hi, > how can i send a signal about an event from a thread to mfc > application. > plz hel...

Need a worker thread framework
Dear all, I am searching for a worker thread framework.If you know some, please help. Thanks, Yamaha What is a "worker thread framework"? You can look at my MVP Tips site, but I'm not sure what a "framework" would do. There is an MFC framework in which threads live, but this doesn't seem to be a "worker thread framework" joe On Fri, 18 Jul 2003 11:06:29 +0900, "Yamaha" <satma74@yahoo.co.jp> wrote: >Dear all, > >I am searching for a worker thread framework.If you know some, please help. >Thanks, >Yamaha Joseph M. Ne...

Formatting Replies so Reply is seen first rather than after thread
When I reply to emails my response is all the way at the bottom of the email chain so the person receiving it has to scroll all the way to the bottom to see my response. How do I revise the formatting so that replies appear at the top with the email being responded to coming after my response? Alt+ T, Options, Advanced, uncheck Reply on the bottom of a message. -- Ron Sommer MS MVP-Mail "legaleyes" <legaleyes@discussions.microsoft.com> wrote in message news:64C78A1C-0BFC-4268-9A7E-5A06F0C4E241@microsoft.com... > When I reply to emails my response is all th...

Office Communicator- Can you create Chat Rooms within Communicator
I need to cross boarders with a live Chat room. I need to find out how I can initiate a chat room for a group of 50 or 60 people. Can anyone assist me? Can Communicator do this. ...

Money for Imate and Nokia communicator 9300
I want to know if there exists a version of Money for I-mate and Nokia communicator 9300 ...