Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

vc++ windows form application threading

$
0
0

Hi ,

I need to create a thread which contains an endless loop. During each loop a serialport is read. Here is what I have so far:

static void SafeThread1(System::Object ^obj) { char* directory; bool endloop; int ADC_read; ofstream myStream ; int m=1; myStream.open(directory); myStream<<"ADC1;ADC2;ADC3;ADC4;ADC5;ADC6;ADC7;ADC8"<<endl; Form1 ^ob = (Form1^) obj; while(endloop=false){ ADC_read = this->serialPort1->ReadByte(); myStream<<ADC_read<<";"; m++; if(m==7){ myStream<<endl; m=0; } } }

static void ThreadProc1(System::Object ^obj)
     {

        SafeThread1(obj);
    }

I start the thread in:

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {

// TO DO


Thread^ newThread1 = gcnew Thread(gcnew ParameterizedThreadStart(&ThreadProc1 ));
							newThread1->Start(this);

}

and I stop it using :

private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e){
             endLoop = true;

private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e){ 
			 endLoop = true;}

Apparently, I cannot use "this" in a static member function and if I remove static before the void safethread1 , I get " 'Data_Logger::Form1::SafeThread1' : illegal call of non-static member function" . Can someone help me out?

Thanks in advance


Viewing all articles
Browse latest Browse all 12583

Trending Articles