It's working fine, but I'm wondering is it a safe thing to do? This is just a test, modifying one byte at a time in a 64 byte array. In the final version it will be changing all 64 bytes at once.
myThread.h
Code: Select all
#include "wx/wx.h"
// the ID we'll use to identify our event
const int THREAD_STARTED_ID = 100000;
const int THREAD_DATA_UPDATE_ID = 100001;
const int THREAD_STOPPED_ID = 100002;
// a thread class that will periodically send events to the GUI thread
class MyThread : public wxThread
{
wxFrame* m_parent;
unsigned char * ucExternDataArray;
public:
// ucDataArray Is the address of the array in the main thread
MyThread(wxFrame* parent, unsigned char * ucDataArray)
{
m_parent = parent;
ucExternDataArray = ucDataArray;
}
virtual ExitCode Entry();
};
Code: Select all
#include "myThread.h"
wxThread::ExitCode MyThread::Entry()
{
wxCommandEvent eventStart( wxEVT_COMMAND_TEXT_UPDATED, THREAD_STARTED_ID );
wxCommandEvent eventNewData( wxEVT_COMMAND_TEXT_UPDATED, THREAD_DATA_UPDATE_ID );
wxCommandEvent eventStop( wxEVT_COMMAND_TEXT_UPDATED, THREAD_STOPPED_ID );
// Generate event indicating that thread has started
m_parent->GetEventHandler()->AddPendingEvent(eventStart);
for(int x = 0; x < 64; x++)
{
// Add new value to external array at index x
*(ucExternDataArray + x) = (unsigned char)x;
// Add to event the index (in external array) of the new data
eventNewData.SetInt(x);
// Generate event indicating new data available
m_parent->GetEventHandler()->AddPendingEvent( eventNewData );
this->Sleep(500);
if(TestDestroy())
x = 64;
}
// Generate event indicating that thread is stopping
m_parent->GetEventHandler()->AddPendingEvent(eventStop);
return 0;
}