![Avatar](https://opcfoundation.org/wp-content/uploads/sp-resources/forum-avatars/defaults/userdefault.png)
04/19/2020
![sp_UserOfflineSmall](https://opcfoundation.org/wp-content/sp-resources/forum-themes/reboot/images/darkpack/sp_UserOfflineSmall.png)
I everyone i created a thread in OPC Ua C++ pub/sub stack using CreateThread() function when i created the thread
//main.cpp
int main()
{
hThread1 = CreateThread(NULL, 0, DAQ_Thread1, &dwThrdParam1, 0, &dwThreadId1);
}
//thread.cpp
DWORD WINAPI DAQ_Thread1(LPVOID lpParam)
{
Initialzitaion();
Sleep(250); //in milisec
}
//clinet.cpp
void Initialzitaion(){
char* szAppPath = getAppPath();
printf("****************Starting the opc ua client*******************
");
// Initialize the UA Stack platform layer
/*************************************************************************************************************
Note:
None of the OpcUa_xxx functions can be used before the platform layer is assigned to the stack with this method.
*************************************************************************************************************/
ret = UaPlatformLayer::init();
printf("*************OPC UA Stack initialzed successfull*****************
");
if (ret == 0)
{
// Initialize global variables and read configuration
UaString sIniFileName = UaString("%1/ClientConfig.ini").arg(szAppPath);
g_pClientSampleConfig = new ClientSampleConfig;
g_pClientSampleConfig->loadConfiguration(sIniFileName, szAppPath);
g_pUaSession = NULL;
g_pCallback = NULL;
g_nsIndex = OpcUa_UInt16_Max;
g_nsIndex2 = OpcUa_UInt16_Max;
Demo::DataTypes::registerStructuredTypes();
#if CLIENT_CPP_SDK_ACTIVATE_TRACE
/* Activate client trace*/
LibT::initTrace(UaTrace::Data, 10000, 5, "uaclient.log", "OPCuaClient");
LibT::setTraceActive(true);
/* Set Trace Settings for stack*/
LibT::setStackTraceActive(true);
OpcUa_Trace_ChangeTraceLevel(OPCUA_TRACE_OUTPUT_LEVEL_DEBUG);
#endif /* CLIENT_CPP_SDK_ACTIVATE_TRACE */
g_pCallback = new Callback;
#if OPCUA_SUPPORT_PKI
status = g_pClientSampleConfig->setupSecurity(sessionSecurityInfo);
#endif // OPCUA_SUPPORT_PKI
// Setup UserToken - UserPassword
if (g_pClientSampleConfig->userTokenType() == OpcUa_UserTokenType_UserName)
{
sessionSecurityInfo.setUserPasswordUserIdentity(g_pClientSampleConfig->sUsername(), g_pClientSampleConfig->sPassword());
printf("UserName and Password Security setup successfull
");
}
#if OPCUA_SUPPORT_PKI
// Setup UserToken - Certificate
else if (g_pClientSampleConfig->userTokenType() == OpcUa_UserTokenType_Certificate)
{
sessionSecurityInfo.setCertificateUserIdentity(g_pClientSampleConfig->userCertifiate(), g_pClientSampleConfig->userPrivateKey());
}
#endif // OPCUA_SUPPORT_PKI
// We treat anything else as Anonymous
else
{
sessionSecurityInfo.setAnonymousUserIdentity();
}
printf("sessionSecurityInfo Security policy %s
", sessionSecurityInfo.sSecurityPolicy.toUtf8());
//Function to connect to the client
connect(sUrl, sessionSecurityInfo);
}
the code gets stoped after printing this printf("****************Starting the opc ua client*******************
");
1. can we use the CreateThread() function of windows to create a thread
2 . Is their any opc ua thread creation function
1 Guest(s)