I appreciate any help. I have posted my code below: void CFileChangeEvent::stopProcessThread() { TRACE( "> > > > CFileChangeEvent::stopProcessThread() entered - Event handles < %X, %X >, Event ID < %s >\n", m_hProcessStopEvent, m_hProcessRespEvent, getIdentifier() ); // The ProcessStopEvent is used by the main thread to tell the worker thread to stop. // In turn, the worker thread sets the ProcessRespEvent to tell the main thread that it has stopped. ::SetEvent( m_hProcessStopEvent ); } UINT CFileChangeEvent::MultiFileProcessThread( LPVOID lpParam ) { // This is the threaded multi-file processor. It searches for and processes all raw flight data // (*.FIF files) in the Inbox or until it is cancelled by a call from DataMovement due to // a Cancel message from PC-GBS. CFileChangeEvent* pEvent = (CFileChangeEvent*)lpParam; CFlightDataHandler* pFlightDataHandler = NULL; CLogWriter* pLogWriter = NULL; HANDLE hProcessStopEvent = pEvent->getProcessStopEvent(); HANDLE hProcessRespEvent = pEvent->getProcessRespEvent(); // We use this exception handling merely to protect this service // from being crashed by an unhandled exception. Errors are // generally handled and logged within the DLL by the LogWriter. try { CDataMovement* pDataMovement = pEvent->getDataMovementParent(); CLogWriter* pLogWriter = pDataMovement->getLogWriter(); pFlightDataHandler = new CFlightDataHandler( pLogWriter ); // We must call ::CoInitialize() each time the database is accessed HRESULT hRes = ::CoInitialize(NULL); CString strInboxPath( pDataMovement->getInboxPath() ); vector<CString> vecFifFiles = UtilK::findAllFiles( "*.fif", strInboxPath ); // The input file parameter points to a single *.fif file, but we // need to extract the folder just below the Inbox path so that // all flight data in that path can be processed int nLen = strInboxPath.GetLength() + 1; vector<CString>::iterator iterFile = vecFifFiles.begin(); CString strFile = *iterFile; CString strLastPath = (*iterFile).Mid( 0, strFile.Find( "\\", nLen ) ); int nFileCount = 0; bool bCancelled = false; for( ; iterFile != vecFifFiles.end() && ! bCancelled; iterFile++ ) { CString strPath = UtilK::getFsPart( *iterFile, UtilK::FsPath ); pFlightDataHandler->importRawFlightData( strPath ); DWORD dwWaitStatus = ::WaitForSingleObject( hProcessStopEvent, 1 ); if ( dwWaitStatus == WAIT_FAILED
RoyceF
Posts
-
Threads in Windows service -
Threads in Windows serviceI have re-posted this in the C++/MFC forum. I would move it if I could. Thanks.
-
Threads in Windows serviceI have a Windows service in which I need to stop worker threads from my main thread. I am trying to use events to do this but I am stumped on why it is not working. Each class that runs a worker thread creates a stop event and a response event. When I need to stop the worker thread I call into the threads class and set the event. However, instead of the worker thread detecting that the event has been set and stopping gracefully, it just disappears. Why? What is the best method for stopping a worker thread from the main thread? Re-posted from the C# forum.
-
Threads in Windows serviceSorry, I thought I was in the C++/MFC forum.
-
Threads in Windows serviceI am wondering if the WaitForSingleObject() doesn't work if the event gets set before WaitForSingleObject() is called. It seems that it would just return the correct status of the event object.
-
Threads in Windows servicevoid CFileChangeEvent::stopProcessThread() { TRACE( "> > > > CFileChangeEvent::stopProcessThread() entered - Event handles < %X, %X >, Event ID < %s >\n", m_hProcessStopEvent, m_hProcessRespEvent, getIdentifier() ); // The ProcessStopEvent is used by the main thread to tell the worker thread to stop. // In turn, the worker thread sets the ProcessRespEvent to tell the main thread that it has stopped. ::SetEvent( m_hProcessStopEvent ); } UINT CFileChangeEvent::workerThread( LPVOID lpParam ) { CFileChangeEvent* pEvent = (CFileChangeEvent*)lpParam; HANDLE hProcessStopEvent = pEvent->getProcessStopEvent(); for( ; iterFile != vecFifFiles.end() && ! bCancelled; iterFile++ ) { Do some work here DWORD dwWaitStatus = ::WaitForSingleObject( hProcessStopEvent, 1 ); if ( dwWaitStatus == WAIT_FAILED ) { TRACE( "> > > > CFileChangeEvent::workerThread() - ::WaitForSingleObject() failed - Event handle < %X >\n", hProcessStopEvent ); bCancelled = true; } else if ( dwWaitStatus == WAIT_OBJECT_0 ) bCancelled = true; } }
Thanks for your help. -
Threads in Windows serviceI have a Windows service in which I need to stop worker threads from my main thread. I am trying to use events to do this but I am stumped on why it is not working. Each class that runs a worker thread creates a stop event and a response event. When I need to stop the worker thread I call into the threads class and set the event. However, instead of the worker thread detecting that the event has been set and stopping gracefully, it just disappears. Why? What is the best method for stopping a worker thread from the main thread?
-
Icon in system trayHi, I am re-posting this because I am still having this problem and I am desperate to figure it out. I am trying to create a tray icon. I downloaded Chris Maunder's project and it works for me in my test dialog which is modal. Now I am trying to get it to work in a modeless dialog that ultimately I want to be hidden. I cannot get the tray icon create logic to work. The call to ::Shell_NotifyIcon() fails but I have no idea why. The NOTIFYICONDATA struct seems to be filled in correctly and GetLastError() returns 0. I have tried it with and without a visible modeless dialog. I need the tray icon only to let my user know that my service is running. My code is below. I call the logic to create the icon below:
m_iconTray.Create( this, WM_ICON_NOTIFY, // Icon notify message to use _T("AutoFileHandler is running"), // tooltip to use ::LoadIcon( NULL, IDI_ASTERISK ), // Icon to use IDR_TRAYICON ); // ID of tray icon
The Icon Create() logic:m_tnd.cbSize = sizeof(NOTIFYICONDATA); m_tnd.hWnd = pParent->GetSafeHwnd()? pParent->GetSafeHwnd() : m_hWnd; m_tnd.uID = uID; m_tnd.hIcon = icon; m_tnd.uFlags = NIF_ICON | NIF_TIP; // NIF_MESSAGE; m_tnd.uCallbackMessage = uCallbackMessage; _tcscpy(m_tnd.szTip, szToolTip); // Set the tray icon VERIFY(m_bEnabled = ::Shell_NotifyIcon(NIM_ADD, &m_tnd));
Any help appreciated -
Delay Windows shutdownThanks everyone for the help. The AbortShutdown() is what I was looking for. I know about the WM_QUERYENDSESSION message and how to handle it. Originally, I was looking for a way to get around the hidden window in my service, but because I have to interact with my user, I must use it.
-
Windows service fails to startYes, I have tried starting the service from the services snapin, then attaching the debugger. It is always stuck in this loop waiting for a change in the current state. I have also stepped into the code from the Winmain entrance and it goes directly to this wait loop. However, I will have to wait until Monday as I can't uninstall the service remotely in order to restart it and I am not at my workstation. So I will pursue this then. Thanks for your help.
-
Windows service fails to startWhen I try to start it from the services panel, it just hangs for 2 or 3 minutes before the system shows a dialog indicating that the service failed to start. StartService() doesn't fail, nor does QueryServiceStatus(). QueryServiceStatus() puts zeros in the exit code variables dwWin32ExitCode and dwServiceSpecificExitCode of the SERVICE_STATUS struct. It just never exits the loop waiting for the m_ssStatus.dwCurrentState to change from SERVICE_START_PENDING. GetLastError() always returns 0.
-
Windows service fails to startHi, I have a Windows service that I had running yesterday, but today I can't get it to start. I have gone back to my old code that ran yesterday, but it still doesn't start. How can I get an error code that will give me some hint of what the problem is? The failing code is shown below:
if( ::StartService(schService, 0, 0) ) { Sleep(1000); while( ::QueryServiceStatus(schService, &m_ssStatus) ) { if( m_ssStatus.dwCurrentState == SERVICE_START_PENDING ) { TRACE( "." ); **THIS LOOP NEVER EXITS, SO I CAN'T GET AN ERROR CODE** Sleep( 1000 ); } else break; }
I found an event in the application event log with the following description, but I don't know what it means: The description for Event ID ( 0 ) in Source ( AutoFileHandler ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details. The following information is part of the event: Service installed. Can anybody help me with this? Any help greatly appreciated. -
gettin' jiggy with itHi, Mike, I know that it has been over three years since you posted this request for help in getting an application to autorun from a USB drive, but did you ever find a solution to the problem. I am trying to do the same thing. You mentioned writing a hook application to do this. Did you do that? What did you hook? Some kind of volume mounted event? I haven't written a hook application, so if you could share any information that you have, I would appreciate an email to rfickling@iac-onlime.com. Thanks, Royce
-
Autorun on USB deviceYes, it is interesting. I can't figure out what might distinguish your system from mine. I am running WinXp Pro SP2. Do you have some sort of 3rd party or MS application that supports this functionality? I downloaded an application from another website that gives me this functionality, but I would have to propagate that application to every platform in our network in order for this to work. Not workable! Thanks for your help, Royce
-
Autorun on USB deviceThanks, guys. However, to quote from MSDN: Autorun.inf files are not supported under Microsoft Windows XP for drives that return DRIVE_REMOVABLE from GetDriveType. It just doesn't work.
-
Autorun on USB deviceHi, I need to make an application autorun from a USB device. Can that be done without being dependent on another application on the host system? I have seen some posts in this forum from '03, but it seems the poster never got an answer that I could use for my case. I would appreciate any help, Royce
-
Autorun from a USB deviceHi, I need to make an application autorun from a USB device. Can that be done without being dependent on another application on the host system? I have seen some posts in this forum from '03, but it seems the poster never got an answer that I could use for my case. I would appreciate any help, Royce
-
CopyFile problemThanks for the help, guys. I found that my problem was using the double quotes around the file paths and not specifiying a filename in the 2nd parameter. Royce
-
CopyFile problemYes, in the CString.Format() method call you do:
CString str; str.Format( "C:\\Documents and Settings\\rfickling\\My Documents\\Expense Report Form.xls" );
I am actually formatting these file specs into CString variables so that it looks like the following:strSrc = "C:\Documents and Settings\rfickling\My Documents\Expense Report Form.xls"; strDst = "Expense Report Form.xls"
So the command in C++ syntax is:CopyFile( strSrc, strDst, FALSE );
This should work, but I get a 123 error. -
CopyFile problemHi All, This seems such a simple problem, I am embarrassed to ask for help, but I just can't seem to get the syntax correct for the CopyFile command. My application builds a vector of CStrings containing commands in format Copyfile( "source file", "dest file", FALSE ), using double quotes around the file specifications in case there are embedded spaces. The following is one of the commands:
CopyFile( "C:\Documents and Settings\rfickling\My Documents\Expense Report Form.xls", "Expense Report Form.xls", FALSE );
All of these commands fail with an error code of 123, which indicates invalid call syntax. What is wrong here? Can anyone help me with this dumb little problem? Thanks, Royce