thread question #4

How can I determine in a block of code if the thread it's running in is the 
same as the main GUI thread?

I was trying to use GetCurrentThread to get the thread the function is being 
called from.   Not sure how compare that to GUI thread. 


0
eric1954 (161)
12/21/2005 7:58:35 PM
vc.mfc 33608 articles. 0 followers. Follow

2 Replies
710 Views

Similar Articles

[PageSpeed] 12

On Wed, 21 Dec 2005 13:58:35 -0600, "Eric Margheim"
<NOSPAM***eric@prism-grp.com***NOSPAM> wrote:

>How can I determine in a block of code if the thread it's running in is the 
>same as the main GUI thread?
>
>I was trying to use GetCurrentThread to get the thread the function is being 
>called from.   Not sure how compare that to GUI thread. 

What will you do with that information? If you're trying to decide between
SendMessage and PostMessage, see GetWindowThreadProcessId and
GetCurrentThreadId, and compare thread IDs. This will allow you to
implement the equivalent of the CLR's Control.InvokeRequired property,
though using this information tends to be more complicated in the native
world due to the lack of delegates and GC.

If you want to determine the process's main thread, the easiest way is to
run some code in it. For example, initialize a global variable like this:

   const DWORD g_mainThreadID = GetCurrentThreadId();

I don't know how to determine this outside the main thread; you might look
for a way to populate PROCESS_INFORMATION besides calling CreateProcess.

-- 
Doug Harrison
Visual C++ MVP
0
dsh (2498)
12/21/2005 8:20:55 PM
> What will you do with that information? If you're trying to decide between
> SendMessage and PostMessage, see GetWindowThreadProcessId and

Actually it's a work around to prevent a global object from being used 
outside the main thread.

I'll try the GetWindowThreadProcessID

Thanks 


0
eric1954 (161)
12/21/2005 8:36:19 PM
Reply:

Similar Artilces:

SUMIF Question
Can you do a range such as M4:O10? My spreadsheet let me put this in but it is not giving me the correct value. I have a 1 in cell O4 and it is giving me a value of "0" for this formula. =SUMIF('June08 Summary'!$E$4:$E$10,"DM",'June08 Summary'!M4:O10) -- Deb No, sumif and countif will only sum/count M4:M10 in your case. If you want to sum all entries in M4:O10 where E4:E10 regardless if there are multiple entries on the same row you can use =SUMPRODUCT(('June08 Summary'!$E$4:$E$10="DM")*('June08 Summary'!M4:O10)) -- Reg...

Problem with blocking of main thread with other thread
I have a problem with blocking of main thread: My application contains an interpreter and I need to write a debugger for it. The mainframe creates a thread that is interpreting instructions. When I need to break execution of instruction thread, I use WaitForSingleObject(m_WaitEventHandle, INFINITE); in the interpreter thread. Everything works fine until the window is opened from the interpreter. Then the mainframe freezes. When I break execution in VC the call stack for interpreter thread shows: � NTDLL! � KERNEL32! � CDebugManager::CheckBreakpoints() � CInterpreterThread::Run() � _Afx...

Outlook plugin for CRM 4.0
Hello, I have a user that has been running CRM with Outlook 2007 on Windows XP with no problems. Now we just upgraded his LPT to Windows 7 and his CRM Outlook Plugin connection is timing out on him. Is there a way to change the time out setting so it will stay logged in? His Outlook does not have the problem only his CRM. Thanks Steve On Jul 22, 4:58=A0am, Steve <St...@discussions.microsoft.com> wrote: > Hello, > =A0 I have a user that has been running CRM with Outlook 2007 on Windows = XP > with no problems. =A0Now we just upgraded his LPT to Windows 7 and his CR= M ...

Where is my thread?
I posted a question about "Search for a value in multi-dimensionla array" an hour ago; where did that go? On 5/17/2010 17:38, Rick wrote: > I posted a question about "Search for a value in multi-dimensionla array" an > hour ago; where did that go? If you mean the one beginning with "Seach", posted almost half an hour before this one, it is there. :) On 5/17/2010 11:51 AM, Jackie wrote: > On 5/17/2010 17:38, Rick wrote: >> I posted a question about "Search for a value in multi-dimensionla >> array" an >> hour ag...

queue question
I have about a dozen queues that can't send messages. The total message count across these queues is about 46 messages. Why when I look in C:\Program Files\Exchsrvr\Mailroot\vsi 1\Queue don't I see any files? OK, not it appears that all outbound mail has stopped. I have a lot of this in the SMTP virtual server log. What does it mean? 2007-02-09 03:06:04 64.18.7.10 OutboundConnectionResponse SMTPSVC1 MRBSERVER - 25 - - 220+Postini+ESMTP+37+y6_8_11c0+ready.++CA+Business+and+Professions+Code+Section+17538.45+forbids+use+of+this+system+for+unsolicited+electronic+mail+advertisemen...

Email address #4
We've just configured the groupwise mail connector on exchange 2003 to connect our other site who are using groupwise. When we send email to our site, which is routed through the groupwise server, the address from the sender is displayed as: o2.co.uk.matt_hather it should be displayed as: matt_hather@o2.co.uk Any ideas why this would happen? when we reply, we get an undeliverable message back. we are using Outlook XP on each machine. Thanks What you see in ADUC, user properties, General, E-mail? Jim C wrote: > We've just configured the groupwise mail connector on exchan...

Simple Thread
I have created a thread in my MFC Dialog based application, in the thread function i want to have access to a user interface control that is attached to the main dialog. How can I do it? Regards, Mystique Mystique wrote: > I have created a thread in my MFC Dialog based application, in the thread > function i want to have access to a user interface control that is attached > to the main dialog. > How can I do it? > > Regards, > Mystique > > Indirectly, by posting a message to the main thread asking it to update the control. http://www.mvps.org/vcfaq/mfc/12.ht...

2/4 rounded corners?
I wan to create boxes (both text and image) that have the top right and bottom left corners rounded; retaining sharp corners on the top left and bottom right. Can this be done in Publisher? Autoshapes, create a rounded box, copy/paste special as a .wmf. Select the image, Arrange, ungroup, yes, ungroup again, edit points, hold down control, delete the corner points, adjust your lines. You cannot do this with a text box, but you can use your new creation as a border for a text box. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com &q...

Need Help with Busy Dialog Thread
my application would perform a task. I want to stop the user from using the application's GUI untill the the BG task is finished. At first using Modal Dlg did not do the trick as every one now (apart from me) the the CDialog::DoModal() function has to return some how. So, I made a bit of research on the net and found a trick to display the Dialog using CWinThread derived class without stoping the main app window for executing the background task as follows: (1) In your header file define a CWinThread-derived class... class CDialogThread : public CWinThread { DECLARE_DYNCREATE(CDial...

filter question
Hi, I have a filter question. column A needs to stay numerical. ( 1,2,3,4,5,6 etc) Columns b to G need to be filtered in order of Client name ( column B) Can this be done? if so, can it be done automatically or with the help of a macro? Thanks, Nigel make sure that column A is numeric and not the result of an equation. select all that you want to stay together while sorted. select <data><sort> and sort by column B "Nigel" wrote: > Hi, > I have a filter question. column A needs to stay numerical. ( 1,2,3,4,5,6 etc) > Columns b to G need to be filtered in...

Question about Absolute reference formula
Hi everyone. This is my first post here. I just found this place an it looks like a treasure-trove of information. I'm sure I'll b visiting this site quite often. My first question is really a "why" question. It's not a problem, just like to know why this works the way it does. Here's the situation: I have two workbooks open. Workbook 1 (called Test) has this formula in cell A3: =SUM(A1:A2) I want the results of the formula in Workbook 1 pasted in Workbook 2. So I switch to Workbook 2 and click on a cell, type the equal sign an then switch back to Workbook 1 an...

Importing to Outlook #4
How do I transfer my address book, e-mail etc from yahoo to Outlook? You have to export your Yahoo address book in MS Outlook format and then impor the file from Outlook. The wizards in both tools should walk you through it. -- This posting is provided "AS IS" with no warranties, and confers no rights. Please do not send email directly to this alias as it is used for newsgroup participation only. "Neil" <anonymous@discussions.microsoft.com> wrote in message news:1750201c448f2$4bc12090$a301280a@phx.gbl... > How do I transfer my address book, e-mail etc from yah...

Diaglog/Threading Data Exchange Question
Greetings, I have learned a lot from all of you, and I hope to over come my latest road block. I have a smal IRC Chat client I am making. I have a Dialog Box with Control and I use a worker thread for connecting to IRC - That Thread will update controls on the Dialog by sending PostMessages. Now my problem is in the ListBox Control that I have extended to do popup menu with various commands. I need to be able to read that controls methods from within the Thread. so I need to do this from within my IRC Socket thread: (code not exact - pseudo code) CListBoxEx myUsers; //Defined in my ...

Killing thread from outside thread in MFC App
Hi, Thanks to all those who offered advise on my last query. I successfully used the worker thread method to give control back to the dialog box whilst background processing was being carried out. The issue I have now is closing that thread externally. The method I've used to create the thread uses a volatile boolean variable. Whilever it is set to TRUE, the thread remains alive. However, when I set the variable to FALSE from the calling process (user wants to end processing), it has no effect. The thread continues to run. I thought that declaring the variable as 'volatile'...

Question about Autofilter...
Hello All, I am currently filtering a list using the Autofilter function within Excel. Great! However, I would like to produce a Summary Report in a seperate worksheet based on the results of the filter. Does anyone know a method of how to obtain criteria on which the Autofilter is currently filtering on. Eg. If I filter a column based on say the word "EDGE", how can you automatically, obtain this from the autofilter.... Many thanks in advance, Richard Record a macro while you are doing this, select the range and press F5, special and then visible cells only, copy and and past...

Update stored procedure question
We are using VS 2008 and SQL Server 2005. I have a table Spread that has 1 Integer column called SecurityID. I have a stored procedure spUpdateSpread that increment the SecurityID by 1, and returns that value. If more than 1 process call the stored procedure at the same time, will it return the correct SecurityID ? Thank you CREATE TABLE [dbo].[Spread]( SecurityID [int] NOT NULL, PRIMARY KEY NONCLUSTERED ( [SecurityID] ASC ) ) ON [PRIMARY] CREATE PROCEDURE [dbo].[spUpdateSpread] @SecurityID int output as update Spread set SecurityID = SecurityID + 1 select @Secu...

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...

Send Mail question
Hi, I have an Excel macro that, among other things, emails a spreadsheet to 9 recipients using Outlook. Each time it initiates a send procedure, I get an Outlook warning telling me that: A program is trying to automatically send e-mail on your behalf. Do you want to allow this? If this is unexpected, it may be a virus and you should choose "No" I get this for each of the 9 emails and have to choose yes each time. My question is this: I know I can create a distribution list in Outlook, and put all 9 email addresses in it - does anyone know how I can get my macro to use the distri...

Anyone care to offer advice for my Client / Server threading model
I'm a bit of a sockets newbie and not too sure what the established ways of handling CAsyncSockets are. I need to handle two way comms between two or more handheld pcs and a server. WIth the server I've got: 1 Thread polling for new connections 1 Thread per client connection. The client thread is stuck in a loop called from CWinThread::InitInstance and sits and calls the CAsyncSocket::Receive function until something arrives. It uses peekmessage and postmessage in this loop to see if the app wants me to send anything to the client. This is working erratically though - peekmessage know...

BCM to CRM 4.0 data migration
Hi there, Has anyone done BCM to CRM 4.0 conversion? Is there a tool exists to transfer data from BCM to CRM 4.0 like it has for CRM 3.0? Could you bring the Activity across to CRM 4.0? The problem with BCM to CRM 3.0 conversion was that it will bring the activity across but it would not link them back to correct accounts or contacts records in CRM. Please let me know if anyone here has done the conversion from BCM to CRM 4.0, the tool that you used and the challenges that you faced. thanks Kyaw I was able to bring across Accounts linked to Contacts by exporting both to CSV. I ...

Integration Questions
Where do I go or how do I get the CRM to integrate with Great Plains, I think there is supposed to be an integration tool somewhere, but I cannot find it. There is an integration CD which you will have received if you are a CRM partner or customer "Nathan Tidd" <NTiddSPAM@douglas-associates.com> wrote in message news:0d1a01c3b421$ec4437c0$a501280a@phx.gbl... > Where do I go or how do I get the CRM to integrate with > Great Plains, I think there is supposed to be an > integration tool somewhere, but I cannot find it. It is much more than a "Utility", i...

DLL Question #4
Hi Guys, I have a dll that used to include MFC as shared dll. I changed it to use MFC as static libs, and now the generated lib file for my dll doesn't have any exports. I am using __declspec( dllexport) in all the class declerations. Any thoughts? Thanks AliR. On Wed, 24 May 2006 15:37:44 -0500, "AliR" <AliR@online.nospam> wrote: >Hi Guys, > >I have a dll that used to include MFC as shared dll. I changed it to use >MFC as static libs, and now the generated lib file for my dll doesn't have >any exports. I am using __declspec( dllexport) in al...

out of office assistant not working #4
I have Outlook XP and when I set up my out of office assistant by typing a short reply message in the box and then turn it on by clicking on the I am out of the office button, it does not work. I have tested it quite a bit and it never sends back an auto reply. Any help?????? FWIW, the default configuration of Microsoft Exchange 5.5 and newer doesn't permit out of office notifications to leave the organization. The exchange administrator would have to turn it on and it is a tough sell because the feature will introduce mail loops. (if a loop goes unchecked, it can bring down th...

LOG file question #3
Dear, I have 4 thousand log file since 1st June 2006. It's 5MB per each. They occupied 23 GB of the disk space already. How can I set it up purge the log file automatically? Thanks! -david Run a full online backup of Exchange using NTBackup (from the Exchange server or another server with ESM installed) or by using your backup software that has an Exchansge agent. -- Ben Winzenz Exchange MVP MessageOne Read my blog! http://winzenz.blogspot.com http://feeds.feedburner.com/winzenz (RSS Feed) "Cat bite" <Cat_bite@catz.kingdom> wrote in message news:%23WnAmgW0GHA....

Copying iPhoto 4 pictures to WordX
I've searched this groups topics on this subject and never found the right solution my problem. Hope this is sufficient info: Mac ibook G4, OS X 10.3.9. iPhoto 4 4.0.3 (4H2) Word X for Mac upgrade (originally part of Microsoft Office 98) 1983-2001 I have previously been able to copy and drag pictures from iPhoto4 to the Picture file and then copy and paste from Preview into Word and resize as needed. Now it works sometimes, but most of the time not. I either get the picture on the Word document (Yeah!) or I get the message "Quicktime and a tiff decompressor are required to see ...