private void message_worker_task(object sender, DoWorkEventArgs e) { ECLib.ErrorCode err = ECLib.ErrorCode.ERR_NOERROR; try { BackgroundWorker bw = sender as BackgroundWorker; ECLibThreadWork work = e.Argument as ECLibThreadWork; int msg_size = 512; byte[] msg = new byte[msg_size]; while (!bw.CancellationPending) { err = ECLib.BL_GetMessage(work.id, work.channel, msg, ref msg_size); if (err == ECLib.ErrorCode.ERR_NOERROR && msg[0] != '\0') { bw.ReportProgress(0, System.Text.Encoding.ASCII.GetString(msg)); } else if (err != ECLib.ErrorCode.ERR_NOERROR) { bw.ReportProgress((int)err); break; } msg_size = 512; } } finally { e.Result = err; msg_done.Set(); } }
private void data_worker_task(object sender, DoWorkEventArgs e) { ECLib.ErrorCode err = ECLib.ErrorCode.ERR_NOERROR; try { BackgroundWorker bw = sender as BackgroundWorker; ECLibThreadWork work = e.Argument as ECLibThreadWork; bool stop = false; ECLib.DataInfos infos = default(ECLib.DataInfos); ECLib.CurrentValues curr = default(ECLib.CurrentValues); while (!bw.CancellationPending && !stop) { int[] buf = new int[1000]; // needed for each iteration err = ECLib.BL_GetData(work.id, work.channel, buf, ref infos, ref curr); if (err == ECLib.ErrorCode.ERR_NOERROR) { if (infos.NbRows != 0 && infos.NbCols != 0) { bw.ReportProgress(0, new ECLibData { Infos = infos, Curr = curr, Buf = buf }); } if (curr.State != ECLib.ChannelState.KBIO_STATE_RUN) { stop = true; } } else { bw.ReportProgress((int)err); stop = true; } } } finally { e.Result = err; data_done.Set(); } }