private delegate uint StartAddress(IntPtr param);
[DllImport("msvcr100.dll")]
private static extern IntPtr _beginthreadex(IntPtr psa, //安全屬性
uint stacksize, //堆疊大小
StartAddress start, //執行緒函式
IntPtr param, //執行緒函式引數
uint flags, //編輯,0或CREATE_SUSPEND(C++)
ref uint threadID //執行緒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); //委托物件,函式指標
hands[0] = _beginthreadex((IntPtr)0, 0, start, (IntPtr)0, 0, ref unThreadID);
WaitForMultipleObjects(1, hands, true, -1);
}
再exe程式中會卡死
uj5u.com熱心網友回復:
[DllImport("msvcr100.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
static extern uint _beginthreadex(
IntPtr psa, //安全屬性
uint stacksize, //堆疊大小
StartAddress start, //執行緒函式
IntPtr param, //執行緒函式引數
uint flags, //編輯,0或CREATE_SUSPEND(C++)
ref uint threadID //執行緒ID
);_beginthreadex 宣告改一下試試
uj5u.com熱心網友回復:
[DllImport("msvcr100.dll", EntryPoint = "_beginthreadex", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]也是不行的
uj5u.com熱心網友回復:
我做了個小demo,可以,如果你還是“卡死”那就是你方法的問題了,你方法里試著不要彈框,只是寫檔案試試。或你貼出一個你完整代碼,上傳網盤分享過來看看轉載請註明出處,本文鏈接:https://www.uj5u.com/net/268473.html
標籤:C#
上一篇:C# Dataset報錯求助
