本文整理汇总了C#中Worker类的典型用法代码示例。如果您正苦于以下问题:C# Worker类的具体用法?C# Worker怎么用?C# Worker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Worker类属于命名空间,在下文中一共展示了Worker类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ModelTraverser
/// <summary>
/// Initializes a new instance.
/// </summary>
/// <param name="createModel">Creates the model that should be checked.</param>
/// <param name="output">The callback that should be used to output messages.</param>
/// <param name="configuration">The analysis configuration that should be used.</param>
internal ModelTraverser(Func<AnalysisModel> createModel, Action<string> output, AnalysisConfiguration configuration)
{
Requires.NotNull(createModel, nameof(createModel));
Requires.NotNull(output, nameof(output));
TransitionCollection.ValidateTransitionSizes();
var tasks = new Task[configuration.CpuCount];
var stacks = new StateStack[configuration.CpuCount];
_loadBalancer = new LoadBalancer(stacks);
Context = new TraversalContext(_loadBalancer, configuration, output);
_workers = new Worker[configuration.CpuCount];
for (var i = 0; i < configuration.CpuCount; ++i)
{
var index = i;
tasks[i] = Task.Factory.StartNew(() =>
{
stacks[index] = new StateStack(configuration.StackCapacity);
_workers[index] = new Worker(index, Context, stacks[index], createModel());
});
}
Task.WaitAll(tasks);
_states = new StateStorage(_workers[0].Model.StateVectorSize, configuration.StateCapacity);
Context.States = _states;
}
示例2: Run
public void Run()
{
const int num_workers = 4;
Worker[] workers = new Worker[num_workers];
Thread[] threads = new Thread[num_workers];
for (int i = 0; i < num_workers; i++)
{
workers[i] = new Worker(i, 50);
threads[i] = new Thread(workers[i].Run);
threads[i].Start();
}
foreach (Thread t in threads)
t.Join();
foreach (Worker w in workers)
{
foreach (Expr e in w.result)
Console.Write(" " + e);
Console.WriteLine();
}
Console.WriteLine("done");
}
示例3: Main
static void Main()
{
// 创建线程对象。这不会启动该线程。
Worker workerObject = new Worker();
Thread workerThread = new Thread(workerObject.DoWork);
// 启动辅助线程。
workerThread.Start();
Console.WriteLine("main thread: Starting worker thread...");
// 循环直至辅助线程激活。
while (!workerThread.IsAlive);
// 为主线程设置 1 毫秒的休眠,
// 以使辅助线程完成某项工作。
Thread.Sleep(1);
// 请求辅助线程自行停止:
workerObject.RequestStop();
// 使用 Join 方法阻塞当前线程,
// 直至对象的线程终止。
workerThread.Join();
Console.WriteLine("main thread: Worker thread has terminated.");
}
示例4: Enter
internal void Enter(ref Worker wr, Work work) {
work.Next = null;
var owner = Interlocked.Exchange(ref Tail, work);
if (owner != null) {
owner.Next = work;
} else {
Release:
work.DoWork(ref wr);
var prev = work;
work = Volatile.Read(ref prev.Next);
if (null != work)
goto Release;
if (prev == Interlocked.CompareExchange(ref Tail, null, prev))
return;
Spin:
work = Volatile.Read(ref prev.Next);
if (null != work)
goto Release;
goto Spin;
}
}
示例5: Main
public static void Main()
{
string[] studentData = Console.ReadLine()
.Trim()
.Split(new []{' '}, StringSplitOptions.RemoveEmptyEntries);
string firstStudentName = studentData[0];
string lastStudentName = studentData[1];
string facultyNumber = studentData[2];
string[] workerData = Console.ReadLine()
.Trim()
.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
string firstWorkerName = workerData[0];
string lastWorkerName = workerData[1];
double salary = double.Parse(workerData[2]);
double workingHours = double.Parse(workerData[3]);
try
{
Student student = new Student(firstStudentName, lastStudentName, facultyNumber);
Worker worker = new Worker(firstWorkerName, lastWorkerName, salary, workingHours);
Console.WriteLine(student);
Console.WriteLine(worker);
}
catch (ArgumentException ae)
{
Console.WriteLine(ae.Message);
}
}
示例6: Main
public static void Main(string[] args)
{
// Use Release Build to use jsc to generate java program
// Use Debug Build to develop on .net
Console.WriteLine("Robocode1. Crosscompiled from C# to Java.");
// Extension methods...
("This will take a few seconds...").ToConsole();
Text = "Hello World";
var w = new Worker { Count = 3, Delay = 1000 };
w.Handler +=
delegate
{
var n = DateTime.Now;
Console.WriteLine(n.Hour + ":" + n.Minute + ":" + n.Second);
};
w.Invoke();
Console.WriteLine(Text);
}
示例7: Main
public static void Main()
{
var worker = new Worker();
worker.Start();
Thread.Sleep(1000);
worker.Stop();
}
示例8: DoWork
public void DoWork(Worker d)
{
if (!Thread.CurrentThread.Equals((object) this.myThread))
this.app.Dispatcher.Invoke(DispatcherPriority.Normal, (Delegate) d);
else
d();
}
示例9: ConvertWorkerViewModel_WhenValidViewModel_ReturnEntity
public void ConvertWorkerViewModel_WhenValidViewModel_ReturnEntity()
{
var adrConv = new AddressConverter();
var compConv = new CompetenceConverter();
var converter = new WorkerConverter(adrConv,compConv,new ImageConverter());
var viewModel = new WorkerViewModel
{
FirstName = "Filip",
LastName = "Skurniak",
Pesel = "632964328947",
RelianceRating = 10,
WorkerCompetences = new List<CompetenceViewModel>()
{
new CompetenceViewModel
{
Id = 100
}
}
};
var entity = new Worker();
converter.ConvertViewModelToEntity(viewModel, entity);
Assert.AreEqual(entity.FirstName, viewModel.FirstName);
}
示例10: Invoke
public override void Invoke(Worker.State state)
{
foreach (char ch in text)
{
TypeChar(ch);
}
}
示例11: Main
static void Main(string[] args)
{
using (var worker = new Worker("localhost", "console", "failing"))
{
worker.Work();
}
}
示例12: Backend
protected Backend(Object payload, Exception exception, Worker worker, String queue)
{
Exception = exception;
Worker = worker;
Queue = queue;
Payload = payload;
}
示例13: AsWorker
public override Worker AsWorker()
{
Worker worker = new Worker("OTT", "Mathias Henrik Ottosen", 18, true, "Aalborg", "12345678", false, true, true);
worker.SetNotAvailableHours(AsIndisposeds());
return worker;
}
示例14: Invoke
public override void Invoke(Worker.State state)
{
INPUT[] queue = new INPUT[1];
queue[0] = new INPUT();
queue[0].type = InputType.Mouse;
switch (button)
{
case MouseButtons.Left:
queue[0].u.Mouse.Flags |= MouseFlag.LeftUp;
break;
case MouseButtons.Right:
queue[0].u.Mouse.Flags |= MouseFlag.RightUp;
break;
case MouseButtons.Middle:
queue[0].u.Mouse.Flags |= MouseFlag.MiddleUp;
break;
case MouseButtons.XButton1:
queue[0].u.Mouse.Flags |= MouseFlag.XUp;
queue[0].u.Mouse.MouseData |= (ushort)XButton.XButton1;
break;
case MouseButtons.XButton2:
queue[0].u.Mouse.Flags |= MouseFlag.XUp;
queue[0].u.Mouse.MouseData |= (ushort)XButton.XButton2;
break;
}
NativeMethods.SendInput(1, queue, Marshal.SizeOf(typeof(INPUT)));
}
示例15: FormLoader
public FormLoader(Plugin plugin, RecordReader stockReader, bool lazyLoading, int backgroundJobs)
{
if (backgroundJobs < 0)
throw new ArgumentException("Number of bakcground jobs must be a positive integer or zero");
sharedData = new SharedData()
{
Plugin = plugin,
StockReader = stockReader,
LazyLoading = lazyLoading,
FormsToLoad = new BlockingCollection<Form>(new ConcurrentQueue<Form>(), 1024),
WorkerCompleteEvent = new AutoResetEvent(false)
};
this.stockReader = stockReader;
asyncLoading = backgroundJobs > 0;
bool useStockReader = true;
while (backgroundJobs-- > 0)
{
Worker worker = new Worker(sharedData, useStockReader);
worker.RunWorkerCompleted += Worker_RunWorkerCompleted;
worker.RunWorkerAsync();
workers.Add(new WorkerInfo()
{
Worker = worker
});
// Only the first worker can use the stock reader
useStockReader = false;
}
}