0
計算が必要なレコードストリームがあるとします。レコードは、これらの機能の組み合わせをSum
,Aggregate
,Sum over the last 90 seconds
、またはignore
の順に実行します。どのように、必要があるIDはいくつかの種類のint
であり、そのintは実行するために、いくつかの代表団の行列に対応すると仮定するとソースデータに基づいて代理人を動的にロードして呼び出す
Date;Data;ID
質問
:
データレコードは次のようになります私はC#を使ってその起動マップを動的に構築していますか?
私はこの考えが存在すると確信しています...多くのデリゲート/イベントを持つWindowsフォームで使用されていますが、そのほとんどは実際のアプリケーションでは実際には呼び出されません。
以下のサンプルには、(合計、カウント、および印刷)を実行したい代議員がいくつか含まれていますが、ソースデータに基づいてデリゲートの数をどのようにするかわかりません。 (たとえば追いついを印刷し、そしてこのサンプルのオッズを合計)
using System;
using System.Threading;
using System.Collections.Generic;
internal static class TestThreadpool
{
delegate int TestDelegate(int parameter);
private static void Main()
{
try
{
// this approach works is void is returned.
//ThreadPool.QueueUserWorkItem(new WaitCallback(PrintOut), "Hello");
int c = 0;
int w = 0;
ThreadPool.GetMaxThreads(out w, out c);
bool rrr =ThreadPool.SetMinThreads(w, c);
Console.WriteLine(rrr);
// perhaps the above needs time to set up6
Thread.Sleep(1000);
DateTime ttt = DateTime.UtcNow;
TestDelegate d = new TestDelegate(PrintOut);
List<IAsyncResult> arDict = new List<IAsyncResult>();
int count = 1000000;
for (int i = 0; i < count; i++)
{
IAsyncResult ar = d.BeginInvoke(i, new AsyncCallback(Callback), d);
arDict.Add(ar);
}
for (int i = 0; i < count; i++)
{
int result = d.EndInvoke(arDict[i]);
}
// Give the callback time to execute - otherwise the app
// may terminate before it is called
//Thread.Sleep(1000);
var res = DateTime.UtcNow - ttt;
Console.WriteLine("Main program done----- Total time --> " + res.TotalMilliseconds);
}
catch (Exception e)
{
Console.WriteLine(e);
}
Console.ReadKey(true);
}
static int PrintOut(int parameter)
{
// Console.WriteLine(Thread.CurrentThread.ManagedThreadId + " Delegate PRINTOUT waited and printed this:"+parameter);
var tmp = parameter * parameter;
return tmp;
}
static int Sum(int parameter)
{
Thread.Sleep(5000); // Pretend to do some math... maybe save a summary to disk on a separate thread
return parameter;
}
static int Count(int parameter)
{
Thread.Sleep(5000); // Pretend to do some math... maybe save a summary to disk on a separate thread
return parameter;
}
static void Callback(IAsyncResult ar)
{
TestDelegate d = (TestDelegate)ar.AsyncState;
//Console.WriteLine("Callback is delayed and returned") ;//d.EndInvoke(ar));
}
}