本文整理汇总了C#中System.Threading.Task类的典型用法代码示例。如果您正苦于以下问题:C# Task类的具体用法?C# Task怎么用?C# Task使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Task类属于System.Threading命名空间,在下文中一共展示了Task类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Task
public Task(IDataBindEngineClient c, TaskOps o, Task previousForClient)
{
client = c;
op = o;
PreviousForClient = previousForClient;
status = Status.Pending;
}
示例2: StartConstantOutputTask
/// <summary>
/// Start a constant output by the DAQ device. This function starts a task named "OutputTask",
/// Don't forget to stop it when it's no longer needed.
/// </summary>
/// <param name="voltage">the requested voltage to apply</param>
public void StartConstantOutputTask(double voltage)
{
int samplesPerChannel = 2500;
int sampleRate = 2500;
//
// generate output array
//
m_functionGenerator = new FunctionGenerator(samplesPerChannel, voltage, voltage);
//
// get the properties required for the output task
//
ContinuousAOTaskProperties outputProperties = new ContinuousAOTaskProperties(null, sampleRate, samplesPerChannel, voltage);
//
// create the output task
//
m_outputTask = m_daqController.CreateContinuousAOTask(outputProperties);
//
// create the writer of the output task
//
writer = new AnalogSingleChannelWriter(m_outputTask.Stream);
//
// write static voltage
//
writer.WriteMultiSample(true, m_functionGenerator.ConstWave);
}
示例3: DeleteTask
/*
* Delete a Task
*
* @param: TaskDeleted : a callback
* @param: tasklist : string
* @param: t : Task
*/
public void DeleteTask(Action<IRestResponse<Error>> TaskDeleted, string tasklist, Task t)
{
_oAuth.GetAccessCode(access_token =>
{
lock (_sync)
{
_requesting++;
// building request
_client.Authenticator = new OAuth2AuthorizationRequestHeaderAuthenticator(access_token);
var request = new RestRequest("/tasks/v1/lists/" + tasklist + "/tasks/" + t.Id, Method.DELETE);
// serialize Task
string taskJson = JsonConvert.SerializeObject(t, Formatting.None,
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
request.AddParameter("application/json; charset=utf-8", taskJson, ParameterType.RequestBody);
LaunchTimer();
_client.ExecuteAsync<Error>(request, response =>
{
lock (_sync)
{
_requesting--;
// handle request's callback
ObservableCollection<Task> tasks = null;
_tasks.TryGetValue(tasklist, out tasks);
if (tasks != null && response.StatusCode == HttpStatusCode.NoContent && response.Data == null)
{
// delete the task
tasks.Remove(t);
}
if (TaskDeleted != null) TaskDeleted(response);
}
});
}
});
}
示例4: TestCreateNewTask
public async System.Threading.Tasks.Task TestCreateNewTask()
{
UserCredential credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = _clientId,
ClientSecret = _clientSecret
},
new[] { TasksService.Scope.Tasks },
"user",
CancellationToken.None);
var service = new TasksService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = _application
});
TaskLists lists = await service.Tasklists.List().ExecuteAsync();
Assert.IsTrue(lists.Items.Count > 0);
string listId = lists.Items[0].Id;
Task newTask = new Task()
{
Title = "Test",
};
Task result = await service.Tasks.Insert(newTask, listId).ExecuteAsync();
Assert.AreEqual(newTask.Title, result.Title);
}
示例5: AcquisitionStarting
public override void AcquisitionStarting()
{
// initialise the output hardware
outputTask = new Task("analog output");
if (!Environs.Debug)
{
AnalogOutputChannel oc =
(AnalogOutputChannel) Environs.Hardware.AnalogOutputChannels[(string)settings["channel"]];
oc.AddToTask(outputTask, oc.RangeLow, oc.RangeHigh);
writer = new AnalogSingleChannelWriter(outputTask.Stream);
writer.WriteSingleSample(true, 0);
}
scanParameter = 0;
//go gently to the correct start position
if ((string)settings["scanMode"] == "up" || (string)settings["scanMode"] == "updown")
{
if ((string)settings["flyback"] == "overshoot") rampOutputToVoltage((double)settings["overshootVoltage"]);
rampOutputToVoltage((double)settings["start"]);
}
if ((string)settings["scanMode"] == "down" || (string)settings["scanMode"] == "downup")
{
if ((string)settings["flyback"] == "overshoot") rampOutputToVoltage((double)settings["overshootVoltage"]);
rampOutputToVoltage((double)settings["end"]);
}
}
示例6: PerformTask
private static void PerformTask(Task t)
{
CurrentTaskId++;
int tid = CurrentTaskId;
try
{
Thread.BeginCriticalRegion(); // It is important that this task not be stopped here
MinecraftModUpdater.Logger.Log(Logger.Level.Debug, "Running Task Id: " + tid.ToString());
if (t != null)
{
t.Invoke();
MinecraftModUpdater.Logger.Log(Logger.Level.Debug, "Task " + tid.ToString() + " Done");
}
}
catch (Exception e)
{
MinecraftModUpdater.Logger.Log(Logger.Level.Error, "Error on task " + tid.ToString());
MinecraftModUpdater.Logger.Log(e);
MCModUpdaterExceptionHandler.HandleException(t, e);
}
finally
{
Thread.EndCriticalRegion(); // Thread can now be stopped.
}
}
示例7: getAllProjectTasks
/// <summary>
/// Gets all tasks from ProjectFile instance.
/// </summary>
/// <param name="projectFile">ProjectFile instance.</param>
/// <returns>List of tasks.</returns>
protected Task[] getAllProjectTasks(ProjectFile projectFile)
{
//get tasks
java.util.List taskList = projectFile.AllTasks;
//convert to array
object[] allTaskObjs = taskList.toArray();
//create alternate storage
Task[] allTasks = new Task[allTaskObjs.Length];
//then cast each object to a Task
for(int o = 0; o < allTaskObjs.Length; o++)
{
//cast
allTasks[o] = (Task)allTaskObjs[o];
//then nullify the initial value, be nice to your memory and it WILL return the favor
allTaskObjs[o] = null;
}
//nullify primary storage
allTaskObjs = null;
//then return the secondary list, otherwise permit a run-time exception
//this is a wild bunch of magic anyways
return allTasks;
}
示例8: ConfigureReadAI
//AND CAVITY VOLTAGE!!!
//The photodiode inputs have been bundled into one task. We never read one photodiode without reading
//the other.
public void ConfigureReadAI(int numberOfMeasurements, bool autostart)
{
readAIsTask = new Task("readAI");
channels = new Dictionary<string, AnalogInputChannel>();
foreach (string s in analogInputs)
{
AnalogInputChannel channel = (AnalogInputChannel)Environs.Hardware.AnalogInputChannels[s];
channels.Add(s, channel);
}
foreach (KeyValuePair<string, AnalogInputChannel> pair in channels)
{
pair.Value.AddToTask(readAIsTask, 0, 10);
}
if (autostart == false)
{
readAIsTask.Timing.ConfigureSampleClock(
"",
40000,
SampleClockActiveEdge.Rising,
SampleQuantityMode.FiniteSamples, numberOfMeasurements);
readAIsTask.Triggers.StartTrigger.ConfigureDigitalEdgeTrigger(
(string)Environs.Hardware.GetInfo(trigger),
DigitalEdgeStartTriggerEdge.Rising);
}
readAIsTask.Control(TaskAction.Verify);
analogReader = new AnalogMultiChannelReader(readAIsTask.Stream);
}
示例9: Read
public void Read()
{
try {
string[] channelNameList = DaqSystem.Local.GetPhysicalChannels(PhysicalChannelTypes.AI, PhysicalChannelAccess.External);
if (channelNameList.Length > 0) {
Task task = new Task();
task.AIChannels.CreateVoltageChannel(channelNameList[0], "Voltage", AITerminalConfiguration.Differential, 0.0, 10.0, AIVoltageUnits.Volts);
task.Timing.ConfigureSampleClock("", 100000, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples);
task.Control(TaskAction.Verify);
AnalogSingleChannelReader airead = new AnalogSingleChannelReader(task.Stream);
AnalogWaveform<double> waveform;
for(int i=0;i<repeat;i++){
waveform = airead.ReadWaveform(sampleRate);
datalist.AddRange(waveform.GetRawData());
Console.Out.WriteLine("Acquire " + i + "th try");
}
StreamWriter writer = new StreamWriter(File.Open("ai.txt", FileMode.Create));
int c = 0;
foreach (double d in datalist) {
writer.WriteLine(String.Format("{0} {1}",c,d));
c++;
}
writer.Close();
}
} catch (DaqException e) {
Console.Out.WriteLine(e.Message);
}
}
示例10: CreateTaskAsync
public async System.Threading.Tasks.Task<Task> CreateTaskAsync(Task task, string listId)
{
if (_service == null)
{
throw new Exception("Service is not initialized");
}
return await _service.Tasks.Insert(task, listId).ExecuteAsync();
}
示例11: Post
public void Post(Task task)
{
lock (((ICollection)queue).SyncRoot)
{
queue.Add(task);
newItemEvent.Set();
}
}
示例12: Enqueue
public void Enqueue(Action action)
{
var task = new Task
{
TaskWithoutState = action
};
queue.Enqueue(task);
}
示例13: Main
static void Main(string[] args)
{
Task task =new Task();
Thread thread = new Thread(task.DoWork);
thread.Start(1000);
thread.Join();
Console.WriteLine("Summ ={0}",task.Summ);
}
示例14: ConfigureCavityScan
public void ConfigureCavityScan(int numberOfSteps, bool autostart)
{
outputCavityTask = new Task("CavityPiezoVoltage");
cavityChannel =
(AnalogOutputChannel)Environs.Hardware.AnalogOutputChannels[cavityChannelName];
cavityChannel.AddToTask(outputCavityTask, 0, 10);
outputCavityTask.Control(TaskAction.Verify);
cavityWriter = new AnalogSingleChannelWriter(outputCavityTask.Stream);
}
示例15: PooledTaskRunner
public PooledTaskRunner(Task task, int maxIterationsPerRun)
{
this.maxIterationsPerRun = maxIterationsPerRun;
this.task = task;
this._shutdown = false;
this.iterating = false;
this.queued = true;
ThreadPool.QueueUserWorkItem(new WaitCallback(Run), this);
}