Home > Net >  C # thread in C
C # thread in C

Time:03-16

Private delegate uint StartAddress (IntPtr param);

[DllImport (" msvcr100. DLL)]
Private static extern IntPtr _beginthreadex (IntPtr psa,//security attribute
Uint stacksize,//stack size
StartAddress start,//thread function
IntPtr param,//thread function parameter
Uint flags,//edit, 0 or CREATE_SUSPEND (c + +)
Ref uint threadID//thread ID uint
);

[DllImport (" kernel32. DLL)]
Private static extern uint WaitForMultipleObjects (uint nCount,
IntPtr [] lpHandles,
Bool bWaitAll,
Int dwMilliseconds);

[DllImport (" kernel32 ")]
Private static extern UInt32 WaitForSingleObject (IntPtr hHandle, UInt32 dwMilliseconds);

[DllImport (" kernel32. DLL)]
Public extern static bool CloseHandle (IntPtr hObject);


While (true)
{
IntPtr [] hands=new IntPtr [1].
Uint unThreadID=0;

StartAddress start=new StartAddress (Show);//the delegate object, a function pointer
Hands [0]=_beginthreadex (IntPtr) (0, 0, start, IntPtr) (0, 0, ref unThreadID);
WaitForMultipleObjects (1, hands, true, 1);
}
Exe program will be jammed again

CodePudding user response:

 [DllImport (" msvcr100. DLL, "CharSet=CharSet. Auto, CallingConvention=CallingConvention. Cdecl)] 
The static extern uint _beginthreadex (
IntPtr psa,//security attribute
Uint stacksize,//stack size
StartAddress start,//thread function
IntPtr param,//thread function parameter
Uint flags,//edit, 0 or CREATE_SUSPEND (c + +)
Ref uint threadID//thread ID
);


The change try _beginthreadex statement

CodePudding user response:

[DllImport (" msvcr100. DLL, "EntryPoint=" _beginthreadex SetLastError=true, CharSet=CharSet. Auto, ExactSpelling=false, CallingConvention=CallingConvention. StdCall)]
Is no good

CodePudding user response:

I had a small demo, can, if you are "stuck" method that is your problem, you try not to play box method, just write files a try, or you post a complete code, upload share come and look at the cloud
  •  Tags:  
  • C#
  • Related