[ bigguy @ 05.08.2010. 08:58 ] @
Imam ovu klasu: Code (csharp): public class Semaphore { private Mutex[] m_mutex; private Thread[] m_threadIds; private int m_threadLimit; // constructor // parameter - threadLimit (number of threads to control) public Semaphore(int threadLimit) { m_threadLimit = threadLimit; m_mutex = new Mutex[m_threadLimit]; m_threadIds = new Thread[m_threadLimit]; for (int i=0; i<m_threadLimit; i++) { m_mutex[i] = new Mutex(); m_threadIds[i] = null; } } // if there is a timeout then WaitHandle.WaitTimeout is returned // calling thread should check for this public int Wait() { int index = WaitHandle.WaitAny(m_mutex); if (index != WaitHandle.WaitTimeout) m_threadIds[index] = Thread.CurrentThread; return index; } // release the mutex locked by the thread public void Release() { for (int i=0; i<m_threadLimit; i++) { if (m_threadIds[i] == Thread.CurrentThread) { m_mutex[i].ReleaseMutex(); } } } } i imam ovaj kod u MainForm: Code (csharp): public const byte ENQ = 0x05; public static byte[] ENQ_BUFF = { ENQ }; private void btnSend_Click(object sender, EventArgs e) { Thread s = new Thread(new ParameterizedThreadStart(SendX)); s.Start(ENQ_BUFF); } private void SendX(object param) { m_semaphore.Wait(); byte[] msg = (byte[])param; Send(msg); frmDataSend new_frmDataSend = new frmDataSend(); new_frmDataSend.Show(); m_semaphore.Release(); } private void Send(byte[] msg) { //slanje podataka } Moje pitanje je zasto se new_frmDataSend otvori i zatvori odmah? Meni je potrebno da dok god ja new_frmDataSend rucno ne ztvorim da se ona ne gasi. Ono sto je meni potrebno je ono sto se desava kada umesto Code (csharp): stavim Code (csharp): MessageBox.Show("WORK. JEEE!"); Kakava je razlika izmedju MessageBox koji se gasi na OK button i Form koja se gasi na OK button? [Ovu poruku je menjao mmix dana 05.08.2010. u 10:09 GMT+1] |