本文整理汇总了C#中Task.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Task.Dispose方法的具体用法?C# Task.Dispose怎么用?C# Task.Dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Task
的用法示例。
在下文中一共展示了Task.Dispose方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ZeroAOChanOnDev
internal void ZeroAOChanOnDev(string dev, int[] channelsToZero)
{
lock (this)
{
try
{
// Create an analog out task for a given device for all 4 channels.
// Write clearingBufferSize zeros to that port. Wait
// until this is finished and destroy the clearning Task.
Task analogClearingTask = new Task("AnalogClear");
foreach (int chan in channelsToZero)
analogClearingTask.AOChannels.CreateVoltageChannel(
"/" + dev + "/ao" + chan, "", -10.0, 10.0, AOVoltageUnits.Volts);
//analogClearingTask.Timing.ConfigureSampleClock("/" + dev + "/PF",
// clearingSampleRate,
// SampleClockActiveEdge.Rising,
// SampleQuantityMode.FiniteSamples,
// clearingBufferSize);
analogClearingTask.Timing.ReferenceClockSource = ("/" + dev + "/PFI2");
analogClearingTask.Timing.ReferenceClockRate = 10e6;
AnalogMultiChannelWriter analogClearingWriter = new
AnalogMultiChannelWriter(analogClearingTask.Stream);
double[] zeroData = new double[channelsToZero.Length];
analogClearingWriter.BeginWriteSingleSample(false, zeroData, null, null);
analogClearingTask.Control(TaskAction.Verify);
analogClearingTask.Start();
//analogClearingWriter.WriteSingleSample(true, zeroData);
//analogClearingWriter.WriteMultiSample(true, zeroData);
analogClearingTask.WaitUntilDone(30);
analogClearingTask.Stop();
analogClearingTask.Dispose();
analogClearingTask = null;
}
catch (Exception e)
{
Console.WriteLine("Could not zero analog outputs on device: " + dev);
Console.WriteLine(e.Message);
}
}
}
示例2: connected
/// <summary>
/// Tester om Måleenhet er koblet til maskinen.
/// </summary>
/// <returns>bool som er true dersom tilkoblet, false i motsatt tilfelle.</returns>
public static bool connected()
{
bool connected;
// Hvis sensor allerede er i bruk tolkes dette som at sensor er koblet til å i øyeblikket i bruk av tempmåling prosessen.
// Dermed avsluttes metoden her og sier ifra til GUI at sensor (sansynelighvis er koblet til).
// Dette gjøres for å unngå dobbelt sensorbruk som forårsaker feiltolkning i GUI og tempmåling prosessen.
if (Program.sensorInUse) return true;
else
{
Task checkConnection = new Task();
// Tester om programmet klarer å opprette en AIChannel, kun for å se om enhet er koblet til.
try
{
// Dette er en u-elegant måte å teste tilkobling til sensor på.
// Men det er desverre den måten vi har tid og know-how til å implementere.
// Følgende linje er ikke pålitelig nok til dette bruket. Noenganger kaster ikke dette en exception av en eller annen obskur årsak...
checkConnection.AIChannels.CreateThermocoupleChannel("Dev1/ai0", "Temperature", 0, 100,
AIThermocoupleType.J, AITemperatureUnits.DegreesC);
// ...Derfor må dette gjøres for å garantere en exception dersom ikke sensor er koblet til.
AnalogSingleChannelReader reader = new AnalogSingleChannelReader(checkConnection.Stream);
reader.ReadSingleSample(); // Lagrer ikke svar fra sensor, fordi det er denne linjen som kaster exception.
connected = true;
}
catch (Exception)
{
// Bruker ikke error.
connected = false;
}
finally
{
checkConnection.Dispose();
}
return connected;
}
}
示例3: indhentData
//Skraldespanden
//protected override void Dispose(bool disposing)
//{
// if (disposing)
// {
// if (components != null)
// {
// components.Dispose();
// }
// if (myTask != null)
// {
// runningTask = null;
// myTask.Dispose();
// }
// }
// Dispose(disposing);
//}
public void indhentData()
{
if (runningTask == null)
{
try
{
// Create a new task
myTask = new Task();
// Create a virtual channel
myTask.AIChannels.CreateVoltageChannel("Dev1/ai0", "",
(AITerminalConfiguration)(-1), Convert.ToDouble(-3.00),
Convert.ToDouble(3.00), AIVoltageUnits.Volts);
// Configure the timing parameters
// Her bliver samplerate sat til 1000 samt samples per channel til 20
myTask.Timing.ConfigureSampleClock("", Convert.ToDouble(1000),
SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples,10);
// Verify the Task
myTask.Control(TaskAction.Verify);
// Prepare the table for Data
InitializeDataTable(myTask.AIChannels, ref dataTable);
runningTask = myTask;
analogInReader = new AnalogMultiChannelReader(myTask.Stream);
analogCallback = new AsyncCallback(AnalogInCallback); //Håndterer de data vi får ind løbende, selvkørende event
// Use SynchronizeCallbacks to specify that the object
// marshals callbacks across threads appropriately.
analogInReader.SynchronizeCallbacks = true; //Sørger for at sætte trådene til den prioritet som de skal have
analogInReader.BeginReadWaveform(Convert.ToInt32(20),
analogCallback, myTask);
}
catch (DaqException exception)
{
runningTask = null;
myTask.Dispose();
throw exception;
}
}
}
示例4: temp
/// <summary>
/// Gjør en temperatur måling. Dersom det oppstår en feil returnerer metoden 999 og skriver til logg.
/// </summary>
/// <returns>Returnerer temperaturen i double. </returns>
public static double temp()
{
double analogData;
Task temperatureTask = new Task();
try
{
temperatureTask.AIChannels.CreateThermocoupleChannel("Dev1/ai0", "Temperature", 0, 100,
AIThermocoupleType.J, AITemperatureUnits.DegreesC);
AnalogSingleChannelReader reader = new AnalogSingleChannelReader(temperatureTask.Stream);
analogData = reader.ReadSingleSample();
}
catch (Exception e)
{
Logger.Error(e, module); //Logger feil.
analogData = 999;
//999 vil være en "feilkode"
}
finally
{
temperatureTask.Dispose();
}
return analogData;
}
示例5: StartScope
private void StartScope()
{
if (runningTask == null)
{
try
{
// Create a new task
myTask = new Task();
// Create a virtual channel
myTask.AIChannels.CreateVoltageChannel(comboBoxChannel.Text, "",
(AITerminalConfiguration)(-1), Convert.ToDouble(spinEditMinVal.Value),
Convert.ToDouble(spinEditMaxVal.Value), AIVoltageUnits.Volts);
// Configure the timing parameters
myTask.Timing.ConfigureSampleClock("", Convert.ToDouble(sampleRate),
SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, Convert.ToInt32(sampleRead));
// Verify the Task
myTask.Control(TaskAction.Verify);
runningTask = myTask;
analogInReader = new AnalogMultiChannelReader(myTask.Stream);
analogCallback = new AsyncCallback(AnalogInCallback);
// Use SynchronizeCallbacks to specify that the object
// marshals callbacks across threads appropriately.
analogInReader.SynchronizeCallbacks = true;
analogInReader.BeginReadWaveform(Convert.ToInt32(sampleRead),
analogCallback, myTask);
}
catch (DaqException exception)
{
// Display Errors
MessageBox.Show(exception.Message);
runningTask = null;
myTask.Dispose();
}
}
}
示例6: Start
/// <summary>
/// Start.
/// </summary>
public void Start(double period)
{
// Create a new task instance that will be passed to the globally available task.
var _daqtskTask = new Task();
try
{
// Setup Global Sync Clock (GSC).
// Commit before start to speed things up later on when the task needs to be started.
_daqtskTask.COChannels.CreatePulseChannelTime(
"/" + this.m_device + "/" + this.m_counter,
"SampleClock",
COPulseTimeUnits.Seconds,
COPulseIdleState.Low,
0.0,
period * 0.01,
period);
_daqtskTask.Timing.ConfigureImplicit(SampleQuantityMode.ContinuousSamples);
_daqtskTask.Control(TaskAction.Verify);
_daqtskTask.Control(TaskAction.Commit);
// Finally pass the task.
this.m_sampleClock = _daqtskTask;
}
catch (DaqException ex)
{
_daqtskTask.Dispose();
this.m_sampleClock = null;
m_logger.Error("Problem creating SYNC!" + ex.Message);
}
try
{
this.m_sampleClock.Start();
}
catch(DaqException ex)
{
m_logger.Error("Error starting SYNC: " + ex.Message);
}
}
示例7: Task
public void startMåling()
{
if (runningTask == null)
{
try
{
// Create a new task
myTask = new Task();
// Create a virtual channel
myTask.AIChannels.CreateVoltageChannel(DeviceName, "",
(AITerminalConfiguration)(-1), MinimumVolt,
MaximumVolt, AIVoltageUnits.Volts);
// Configure the timing parameters
myTask.Timing.ConfigureSampleClock("", SampleRate,
SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, 1000);
// EVT SAMPLESPRCHANNEL!
// Verify the Task
myTask.Control(TaskAction.Verify);
// Prepare the table for Data
runningTask = myTask;
analogInReader = new AnalogMultiChannelReader(myTask.Stream);
analogCallback = new AsyncCallback(AnalogInCallback);
// Use SynchronizeCallbacks to specify that the object
// marshals callbacks across threads appropriately.
analogInReader.SynchronizeCallbacks = true;
analogInReader.BeginReadWaveform(SamplesPerChannel,
analogCallback, myTask);
}
catch (DaqException exception)
{
// Display Errors
runningTask = null;
myTask.Dispose();
}
}
}
示例8: ZeroPortOnDev
internal void ZeroPortOnDev(string dev, int port)
{
lock (this)
{
try
{
// Create a digital out task for a given device and port.
// Write clearingBufferSize zeros to that port. Wait
// until this is finished and destroy the clearning Task.
Task digitalClearingTask = new Task("DigiClear");
digitalClearingTask.DOChannels.CreateChannel("/" + dev + "/Port" + port, "",
ChannelLineGrouping.OneChannelForAllLines);
//digitalClearingTask.Timing.ConfigureSampleClock("100KHzTimeBase",
// clearingSampleRate,
// SampleClockActiveEdge.Rising,
// SampleQuantityMode.FiniteSamples,
// clearingBufferSize);
DigitalSingleChannelWriter digitalClearingWriter = new DigitalSingleChannelWriter(digitalClearingTask.Stream);
digitalClearingWriter.BeginWriteSingleSamplePort(true,0,null,null);
digitalClearingTask.WaitUntilDone(30);
digitalClearingTask.Stop();
digitalClearingTask.Dispose();
digitalClearingTask = null;
}
catch (Exception e)
{
Console.WriteLine(" Could not zero digital output on device: "
+ dev + "/" + port);
}
}
}
示例9: startButton_Click
private void startButton_Click(object sender, EventArgs e)
{
if (runningTask == null)
{
try
{
stopButton.Enabled = true;
startButton.Enabled = false;
// Create a new task
myTask = new Task();
//create a virtual channel for each checked physical channel.
foreach (var selectedItem in PhysicalChannelListBox.CheckedItems)
{
myTask.AIChannels.CreateVoltageChannel(selectedItem.ToString(), "",
(AITerminalConfiguration)(-1), Convert.ToDouble(minimumValueNumeric.Value),
Convert.ToDouble(maximumValueNumeric.Value), AIVoltageUnits.Volts);
}
// Configure the timing parameters
myTask.Timing.ConfigureSampleClock("", Convert.ToDouble(rateNumeric.Value),
SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, 1000);
// Verify the Task
myTask.Control(TaskAction.Verify);
//wire in LSL
ChannelCount = PhysicalChannelListBox.CheckedItems.Count;
InitializeLSL();
// Prepare the table for Data
InitializeDataTable(myTask.AIChannels, ref dataTable);
acquisitionDataGrid.DataSource = dataTable;
runningTask = myTask;
analogInReader = new AnalogMultiChannelReader(myTask.Stream);
analogCallback = new AsyncCallback(AnalogInCallback);
// Use SynchronizeCallbacks to specify that the object
// marshals callbacks across threads appropriately.
analogInReader.SynchronizeCallbacks = true;
analogInReader.BeginReadWaveform(Convert.ToInt32(samplesPerChannelNumeric.Value),
analogCallback, myTask);
}
catch (DaqException exception)
{
// Display Errors
MessageBox.Show(exception.Message);
runningTask = null;
myTask.Dispose();
stopButton.Enabled = false;
startButton.Enabled = true;
}
}
}