PDA

View Full Version : Problems with the implementation of the thread [disphelper, WMI, QThread]



Mr.Woland
27th July 2011, 21:19
In thread run() function I'm using a disphelper (http://disphelper.sourceforge.net/) functional.
This function is implementing a request to WMI for monitor a system events:
Code:

try
{
const wchar_t * Query = (const wchar_t *) this-> TriggerRequest.utf16 ();
dhCheck (dhGetObject (L "winmgmts: {impersonationLevel = impersonate, (Security)}! \ \ \ \. \ \ root \ \ cimv2", NULL, & wmiSvc));
dhCheck (dhGetValue (L "% o", & wmiEventSrc, wmiSvc, L ". ExecNotificationQuery (% S)", Query));
emit this-> TriggerState (this-> TriggerName, 1);
while (TRUE)
{
CDispPtr wmiLatestEvent;
dhCheck (dhGetValue (L "% o", & wmiLatestEvent, wmiEventSrc, L ". NextEvent"));
emit this-> Triggered (this-> TriggerName, this-> GenerateTriggerMsg (wmiLatestEvent), this-> TriggerIcon);
wmiLatestEvent.Dispose ();
}
}
catch (string errstr)
{
ErrorMSG = this-> GenerateErrorMSG (QString:: fromStdString (errstr));
emit this-> TriggerState (this-> TriggerName, -1);
}

problem follows on line
Code:

dhCheck (dhGetObject (L "winmgmts: {impersonationLevel = impersonate, (Security)}! \ \ \ \. \ \ root \ \ cimv2", NULL, & wmiSvc));
fails with the message:


Member:
Function: GetObject
Error In: GetObjectEx
Error: Neioaene? Aneay ioeaea
Code: 800401e4 (http://www.google.ru/search?client=opera&rls=ru&q=Code:+800401e4&sourceid=opera&ie=utf-8&oe=utf-8&channel=suggest)
Source: Application "
But before the program fails with the message Runtime error.
And even earlier (and now) in another application, this code (in multiple threads) working perfectly.
also, in class constructor such code works fine without any problems.
Out of the run() function this code works;
What's the problem?
Environment variables, configuration files (*.pro) (except a list of files) are identical to the working and nonworking applications.
Shl.
Help pliz.
3 days of debuging ....

high_flyer
28th July 2011, 18:03
The error message says that the offending code in the GetObejct() function.
So probably a parameter or parameters you give to the function, or some other conditions are not valid.
Maybe it has to do with the fact this is threaded, and you are corrupting data from another thread?
Its impossible to know with out an in depth knowledge of your application.
But it does not look like the problem has to do with Qt, rather with how your application works.


And even earlier (and now) in another application, this code (in multiple threads) working perfectly.
also, in class constructor such code works fine without any problems.
Out of the run() function this code works;
In and out of the run() method the thread affinity is very different for objects created with in the scope of the run() method.
Read about QThread thread affinity.
Probably this is causing your your problems - that is, you probably are using thread affinity not as you should.
P.S
Please is spelled S p l e a s e, and not pliz.