本文整理汇总了C#中System.Threading.ManualResetEvent.Count方法的典型用法代码示例。如果您正苦于以下问题:C# ManualResetEvent.Count方法的具体用法?C# ManualResetEvent.Count怎么用?C# ManualResetEvent.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.ManualResetEvent
的用法示例。
在下文中一共展示了ManualResetEvent.Count方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Inference
public static TreeScore Inference(
int num_bootstraps,
InputSample[][] resamples,
Dictionary<AST.Range, InputSample> initial_inputs,
Dictionary<AST.Address, string> initial_outputs,
AST.Range[] input_arr,
AST.Address[] output_arr,
DAG dag,
bool weighted,
double significance,
ProgBar pb)
{
// synchronization token
object lock_token = new Object();
// init thread event notification array
var mres = new ManualResetEvent[input_arr.Length];
// init job storage
var ddjs = new DataDebugJob[input_arr.Length];
// init started jobs count
var sjobs = 0;
// init completed jobs count
var cjobs = 0;
// last-ditch effort flag
bool last_try = false;
// init score storage
var scores = new TreeScore();
for (int i = 0; i < input_arr.Length; i++)
{
try
{
#region BOOTSTRAP
// bootstrapping is done in the parent STA thread because
// the .NET threading model prohibits thread pools (which
// are MTA) from accessing STA COM objects directly.
// alloc bootstrap storage for each output (f), for each resample (b)
FunctionOutput<string>[][] bs = new FunctionOutput<string>[initial_outputs.Count][];
for (int f = 0; f < initial_outputs.Count; f++)
{
bs[f] = new FunctionOutput<string>[num_bootstraps];
}
// init memoization table for input vector i
var memo = new BootMemo();
// fetch the input range TreeNode
var input = input_arr[i];
// fetch the input range COM object
var com = dag.getCOMRefForRange(input).Range;
// compute outputs
// replace the values of the COM object with the jth bootstrap,
// save all function outputs, and
// restore the original input
for (var b = 0; b < num_bootstraps; b++)
{
// lookup outputs from memo table; otherwise do replacement, compute outputs, store them in table, and return them
FunctionOutput<string>[] fos = memo.FastReplace(com, dag, initial_inputs[input], resamples[i][b], output_arr, false);
for (var f = 0; f < output_arr.Length; f++)
{
bs[f][b] = fos[f];
}
}
// restore the original inputs; faster to do once, after bootstrapping is done
BootMemo.ReplaceExcelRange(com, initial_inputs[input]);
// TODO: restore formulas if it turns out that they were overwrittern
// this should never be the case
#endregion BOOTSTRAP
#region HYPOTHESIS_TEST
// cancellation token
mres[i] = new ManualResetEvent(false);
// set up job
ddjs[i] = new DataDebugJob(
dag,
bs,
initial_outputs,
input_arr[i],
output_arr,
weighted,
significance,
mres[i]
);
sjobs++;
// hand job to thread pool
ThreadPool.QueueUserWorkItem(ddjs[i].threadPoolCallback, i);
#endregion HYPOTHESIS_TEST
//.........这里部分代码省略.........
示例2: Start
public void Start()
{
var controller = ConnectsterController.Instance();
while (true)
{
if (_killToken)
{
break;
}
var userList = controller.GetAllUsers();
Log.InfoFormat("Found {0} ShopsterifyUsers, beginning sync for each user.", userList.Count);
//Todo: add call to update sleepUntil Timestamps on users (based on how long they should sleep).
//todo: Also throughout code, we should add points where the user should sleep
// such as in shopifycommunicator, if they have used up their call limit (per 10 mins)
// then we should sleep that user for 10 mins
var actions = 0;
var myJobs = new List<ConnectsterSyncJob>(userList.Count);
var resetEvents = new ManualResetEvent[userList.Count];
for (var i = 0; i < userList.Count; i++)
{
resetEvents[i] = new ManualResetEvent(false);
//TODO: refactor code so it will sleep a certain user, but keep others active
var job = new ConnectsterSyncJob(controller, userList[i], resetEvents[i]);
myJobs.Add(job);
ThreadPool.QueueUserWorkItem(job.ThreadStart, null);
}
if (resetEvents.Count() > 0)
{
WaitHandle.WaitAll(resetEvents);
}
foreach (var job in myJobs)
{
Log.InfoFormat("Job({0},{1}) had {2} actions", job.myUser.ShopsterUser, job.myUser.ShopifyUser,
job.actionsPerformed);
actions += job.actionsPerformed;
}
var sleepTimer = SleepTime;
if (actions == 0)
{
//Double the amount of time we sleep if there was nothing to do last time.
//Maxes out at 4.3 minutes and stays there until something happens.
if (sleepTimer < 262144)
{
sleepTimer *= 2;
}
}
else
{
sleepTimer = 1024; //1 second
}
Log.InfoFormat("Completed {0} actions going to sleep for {1} ms.", actions, sleepTimer);
Thread.Sleep(sleepTimer);
}
// ReSharper disable FunctionNeverReturns
}