public SingleThreadStressTest(ConnectionString connectionString) : base(connectionString) { _client = BrightstarService.GetClient(connectionString); _storeName = connectionString.StoreName; _importJobs = new List <string>(); _queryTimes = new ConcurrentQueue <Tuple <long, int> >(); _queryTasks = new List <Task>(); }
public SingleThreadStressTest(ConnectionString connectionString) : base(connectionString) { _client = BrightstarService.GetClient(connectionString); _storeName = connectionString.StoreName; _importJobs = new List<string>(); _queryTimes = new ConcurrentQueue<Tuple<long, int>>(); _queryTasks = new List<Task>(); }
private Socket(Line Line) { _SendTasks = new ConcurrentQueue <Task>(); _ReadTask = new Task(); m_Line = Line; m_Machine = new StageMachine <Timestamp>(); }
/// <summary> /// Constructor responsible for initializing received messages's list and server's member. /// Already calls .start() function in order to start server's thread. /// </summary> /// <param name="listeningport">Port in configuration file</param> public Networking(int listeningport) { _untreatedInbox = new ConcurrentQueue <byte[]>(); _treatedInbox = new ConcurrentQueue <Message>(); _sendInbox = new ConcurrentQueue <MessageContainer>(); _listeningServer = new Server(listeningport, ref _untreatedInbox); Start(); }
/// <summary> /// 初始化各种处理器 /// </summary> /// <param name="factory">Session工厂</param> /// <param name="filter">连接过滤器</param> /// <param name="handshake">握手处理器</param> public AsyncTcpListener(ISessionFactory factory, ISocketFilter filter, IHandshake handshake) { m_sessionFactory = factory; m_filter = filter; m_handshake = handshake; if (m_filter != null && m_filter.IdleMilliseconds > 0) { m_queue = new System.Collections.Concurrent.ConcurrentQueue<StateObject>(); } }
public SerialPorts_ViewModel(SerialPortWrapper.ISerialPorts ports) { this.ports = ports; listener = ports.GetPortListener(); SerialPortNames = new ReadOnlyObservableCollection <string>(new ObservableCollection <string>(this.ports.GetAvailablePortNames())); worker.RunWorkerCompleted += worker_RunWorkerCompleted; worker.DoWork += worker_DoWork; port_events_queue = new ConcurrentQueue <PortEvent>(); listener.event_handler += OnPortEvent; }
/// <summary> /// 构造函数 /// </summary> /// <param name="maxClients">允许的最大连接数</param> /// <param name="receiveBufferSize">每个连接接收数据缓存的大小</param> /// <param name="sendBufferSize">每个连发送收数据缓存的大小</param> /// <param name="sendQueueSize">等待发送数据的最大业务包</param> public SessionFactory(int maxClients, int receiveBufferSize, int sendBufferSize, int sendQueueSize, IBufferProcessor commandReader) { m_receiveBufferSize = receiveBufferSize; m_sendBufferSize = sendBufferSize; m_bufferPool = new System.Collections.Concurrent.ConcurrentQueue<UserBuffer>(); m_receivebuffer = new byte[maxClients * receiveBufferSize]; m_sendbuffer = new byte[maxClients * sendBufferSize]; m_process = commandReader; for (int i = 0; i < maxClients; i++) { var receivebuffer = new Sinan.Collections.BytesSegment(m_receivebuffer, m_receiveBufferSize * i, m_receiveBufferSize); var sendbuffer = new Sinan.Collections.BytesSegment(m_sendbuffer, m_sendBufferSize * i, m_sendBufferSize); UserBuffer helper = new UserBuffer(i, this, receivebuffer, sendbuffer, sendQueueSize); m_bufferPool.Enqueue(helper); } }
void _worker_DoWork(object sender, DoWorkEventArgs e) { WorkerArgs args = (e.Argument as WorkerArgs); if (args == null) { return; } lock (_launchTimingLock) { _lastLaunchInitiatedUtc = DateTime.UtcNow; } _serverIndex = 0; System.Collections.Concurrent.ConcurrentQueue <LaunchItem> globalQueue = args.ConcurrentLaunchQueue; _serverTotal = globalQueue.Count; if (_serverTotal == 0) { return; } LaunchItem launchItem = null; var accountLaunchTimes = _gameSessionMap.GetLaunchAccountTimes(); while (globalQueue.TryDequeue(out launchItem)) { int threadDelayMs = ConfigSettings.GetConfigInt("ThreadGameLaunchDelayMs", 100); Thread.Sleep(threadDelayMs); new Thread((x) => { Thread.CurrentThread.IsBackground = true; launchGameFromItem(args, (LaunchItem)x, accountLaunchTimes); }).Start(launchItem); if (_worker.CancellationPending) { e.Cancel = true; return; } } }
public MainWindow() { try { InitializeComponent(); TestBenchLogQ = new System.Collections.Concurrent.ConcurrentQueue <string>(); TransmitterLogQ = new System.Collections.Concurrent.ConcurrentQueue <string>(); Logger.DoWork += Logger_DoWork; Logger.WorkerSupportsCancellation = true; Logger.RunWorkerAsync(); Communicator.DoWork += Communicator_DoWork; Communicator.WorkerSupportsCancellation = true; String testbenchport = ConfigurationManager.AppSettings.Get("TestBenchPort"); String testPressure = ConfigurationManager.AppSettings.Get("TestPressure"); Convert.ToDouble(testPressure); HoseLeakTestBench = new TestBench(testbenchport, 9600, Parity.None, 8, StopBits.One); HoseLeakTestBench.LogQ = TestBenchLogQ; String transmitterport = ConfigurationManager.AppSettings.Get("PressureTransmitterPort"); pressureTransmitterManager = new PressureTransmitterManager(transmitterport, 9600, Parity.None, 8, StopBits.One, 1); pressureTransmitterManager.LogQ = TransmitterLogQ; Communicator.RunWorkerAsync(); } catch (Exception e) { TestBenchLogQ.Enqueue(e.Message); } }
/// <summary> /// Display Message on the application page /// </summary> /// <param name="Message">String to display</param> async void LogMessage(string Message) { if (MessageList == null) MessageList = new System.Collections.Concurrent.ConcurrentQueue<string>(); string Text = string.Format("{0:d/M/yyyy HH:mm:ss.fff}", DateTime.Now) + " " + Message + "\n"; MessageList.Enqueue(Text); System.Diagnostics.Debug.WriteLine(Text); await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { string result; // double h = logs.ActualHeight; while (MessageList.TryDequeue(out result)) { logs.Text += result; if (logs.Text.Length > 16000) { string LocalString = logs.Text; while (LocalString.Length > 12000) { int pos = LocalString.IndexOf('\n'); if ((pos > 0) && (pos < LocalString.Length)) { LocalString = LocalString.Substring(pos + 1); } } logs.Text = LocalString; } } //if (logs.ActualHeight > h) // logs.Height = h; } ); }
void IEntity.SetMoveQ(System.Collections.Concurrent.ConcurrentQueue <Vector3> CV, System.Collections.Concurrent.ConcurrentQueue <Quaternion> CQ) { CQuaternion = CQ; CPosition = CV; }
public async Task <IList <DownloadedSubtitle> > SearchSubtitlesForTVAsync(IList <string> showNameCandidates, int seasonNbr, int episodeNbr, IList <CultureInfo> cultureInfos, System.Collections.Concurrent.ConcurrentQueue <ProviderSignal> cQueue) { _logger.LogTrace($"{GetCaller()}() entered"); List <DownloadedSubtitle> downloadedSubs = new List <DownloadedSubtitle>(); try { if (!_tvShows.Any()) { _logger.LogInformation("No TV shows available."); } else { // Find our target show bool foundShow = false; UpdateTaskDisplay(cQueue, .1, "Searching for TV show..."); _logger.LogDebug($"Searching for subtitles for the following show names: ({String.Join<string>(", ", showNameCandidates).TrimEnd()})"); for (int x = 0; x < showNameCandidates.Count && !foundShow; x++) { string showName = showNameCandidates[x]; var myShow = _tvShows.FirstOrDefault(x => x.Name.Contains(showName, StringComparison.OrdinalIgnoreCase)); if (myShow == null) { _logger.LogDebug($"TV show variation ({x + 1}/{showNameCandidates.Count}) ({showName}) was not in the list of available shows."); } else { foundShow = true; UpdateTaskDisplay(cQueue, .2, $"Matched to series ({showName}). Searching for subtitles for season ({seasonNbr})..."); _logger.LogDebug($"TV show variation ({x + 1}/{showNameCandidates.Count}) ({showName}) was found in the list of available shows."); // Find all subtitles for each episode in the target season List <Episode> eps = null; string SEASON_SUBTITLES_FILENAME = $"{showName}.s{seasonNbr}.cache"; IFormatter formatter = new BinaryFormatter(); Stream stream = null; if (File.Exists(SEASON_SUBTITLES_FILENAME)) { // Load the season info from a file stream = new FileStream(SEASON_SUBTITLES_FILENAME, FileMode.Open, FileAccess.Read); eps = (List <Episode>)formatter.Deserialize(stream); stream.Close(); string infoMsg = $"Season subtitles info read from {SEASON_SUBTITLES_FILENAME}. Downloading..."; _logger.LogDebug(infoMsg); UpdateTaskDetails(cQueue, infoMsg); } else { // Download the list of episodes for this season UpdateTaskDisplay(cQueue, .5, $"{SEASON_SUBTITLES_FILENAME} not found. Downloading show list..."); eps = await _api.GetSeasonSubtitles(myShow.Id, seasonNbr); if (eps.Any()) { stream = new FileStream(SEASON_SUBTITLES_FILENAME, FileMode.Create, FileAccess.Write); formatter.Serialize(stream, eps); stream.Close(); string infoMsg = $"Season subtitles info downloaded and written to {SEASON_SUBTITLES_FILENAME}. "; UpdateTaskDetails(cQueue, infoMsg); } else { _logger.LogInformation($"No episodes for season ({seasonNbr}) were available."); } } if (eps.Any()) { // Find our target episode var myEp = eps.Where(x => x.Number == episodeNbr).FirstOrDefault(); if (myEp == null) { _logger.LogInformation($"No subtitles for series ({showName}) season ({seasonNbr}) episode ({episodeNbr}) were available."); } else { foreach (CultureInfo language in cultureInfos) { // Find our target subtitle. Grab the first english one by default var found = myEp.Subtitles.FirstOrDefault(x => x.Language == language.DisplayName); // Try again using parent language if (found == null) { found = myEp.Subtitles.FirstOrDefault(x => x.Language == language.Parent.DisplayName); } if (found == null) { _logger.LogInformation($"Subtitles for series ({showName}) season ({seasonNbr}) episode ({episodeNbr}) were available, not in the language specified ({language})"); } else { UpdateTaskDisplay(cQueue, .3, $"Found {eps.Count} episodes for season ({seasonNbr}). Episode ({episodeNbr}) subtitle found. Downloading..."); _logger.LogInformation($"Downloading subtitles for series ({showName}) season ({seasonNbr}) episode ({episodeNbr}) in {language}"); var downloadedSub = await _api.DownloadSubtitle(myShow.Id, found.DownloadUri); downloadedSubs.Add(new DownloadedSubtitle() { Contents = downloadedSub.Stream, CultureInfo = language }); _logger.LogInformation($"Successfully retrieved subtitles for series ({showName}) season ({seasonNbr}) episode ({episodeNbr}) in {language}"); } } } } } } if (!foundShow) { string warning = $"Could not find show in list of available shows. Used the following show names: ({String.Join<string>(", ", showNameCandidates).TrimEnd()})"; _logger.LogWarning(warning); } } } catch (Exception ex) { // Log the exception as a debug item, as it's presumably logged/handled up the call stack _logger.LogDebug(ex, $"Exception: {GetCaller()}()"); _logger.LogTrace($"{GetCaller()}() exiting (exception)"); throw; } _logger.LogTrace($"{GetCaller()}() exiting (normal)"); return(downloadedSubs); }
public ConcurrentCircularBuffer(int size) { this._size = size; _buffer = new ConcurrentQueue <string>(); }
public Launcher() { _Operations = new ConcurrentQueue <Operation>(); _Items = new List <T>(); }
public static void ExecuteMain(string nick, IndexArgumentSetup setup, Action prepare_db) { var dbname = String.Format ("DB.{0}", Path.GetFileName(setup.DATABASE)); setup.BINARY_DATABASE = dbname; prepare_db (); // It is required to be already on memory at this point. The reason is to avoid the loading of several instances // of the same database SpaceGenericIO.Load (setup.BINARY_DATABASE); var arglist = new System.Collections.Concurrent.ConcurrentQueue<String> (); arglist.Enqueue ("--save"); arglist.Enqueue (String.Format ("Tab.ApproxIndexes.{0}.{1}.qarg={2}.json", nick, Path.GetFileName (setup.QUERIES), setup.QARG)); /*var arglist = new List<string> () { "--save", String.Format("Tab.{0}.{1}.qarg={2}.json", nick, Path.GetFileName(setup.QUERIES), setup.QARG) */ if (setup.ExecuteSequential) { arglist.Enqueue (Indexes.ExecuteSeq (setup, nick)); } var actionlist = new List<Action> (); // arglist.Add (Indexes.ExecuteSATApprox (setup, nick)); // arglist.Add (Indexes.ExecuteSATForest (setup, nick)); foreach (var max_instances in setup.NeighborhoodHash_MaxInstances) { foreach (var expected_recall in setup.NeighborhoodHash_ExpectedRecall) { var _max_instances = max_instances; var _expected_recall = expected_recall; actionlist.Add (() => { var reslist = Indexes.ExecuteMultiNeighborhoodHash (setup, nick, _expected_recall, _max_instances); foreach (var res in reslist) { arglist.Enqueue(res); } }); } } foreach (var numrefs in setup.KNR_NUMREFS) { foreach (var k in setup.KNR_KBUILD) { foreach (var maxcand_ratio in setup.KNR_MAXCANDRATIO) { var _numrefs = numrefs; var _k = k; var _maxcand_ratio = maxcand_ratio; actionlist.Add (() => { var reslist = Indexes.ExecuteKNRSEQ (setup, nick, _numrefs, _k, _maxcand_ratio); foreach (var res in reslist) { arglist.Enqueue(res); } }); } } } // actionlist.Add (() => { // var resname = Indexes.ExecuteAPG_OptTabuSatNeighborhood (setup, nick); // arglist.Enqueue(resname); // }); // // actionlist.Add (() => { // var resname = Indexes.ExecuteAPG_OptTabuSatNeighborhoodMontecarloStart(setup, nick); // arglist.Enqueue(resname); // }); foreach (var neighbors in setup.OPTSEARCH_NEIGHBORS) { // arglist.Add (Indexes.ExecuteLocalSearchRestarts (setup, nick, dbname, setup.QUERIES, neighbors)); // arglist.Add (Indexes.ExecuteLocalSearchBestFirst (setup, nick, dbname, setup.QUERIES, neighbors)); var _neighbors = neighbors; actionlist.Add (() => { var resname = Indexes.ExecuteApproxGraphOptRestartsIS(setup, nick, _neighbors); arglist.Enqueue(resname); }); actionlist.Add (() => { var resname = Indexes.ExecuteApproxGraphOptRandomRestarts(setup, nick, _neighbors); arglist.Enqueue(resname); }); // actionlist.Add (() => { // var resname = Indexes.ExecuteApproxGraphOptSimplerOptRandomRestarts(setup, nick, _neighbors); // arglist.Enqueue(resname); // }); actionlist.Add (() => { var resname = Indexes.ExecuteMetricGraphGreedy(setup, nick, _neighbors); arglist.Enqueue(resname); }); foreach (var restarts in setup.OPTSEARCH_RESTARTS) { var _restarts = restarts; actionlist.Add (() => { var resname = Indexes.ExecuteApproxGraphIS(setup, nick, _neighbors, _restarts); arglist.Enqueue(resname); }); // actionlist.Add (() => { // var resname = Indexes.ExecuteApproxGraph(setup, nick, _neighbors, _restarts); // arglist.Enqueue(resname); // }); } actionlist.Add (() => { var resname = Indexes.ExecuteLocalSearchGallopingBeam(setup, nick, _neighbors); arglist.Enqueue(resname); }); foreach (var beamsize in setup.OPTSEARCH_BEAMSIZE) { var _beamsize = beamsize; actionlist.Add (() => { var resname = Indexes.ExecuteLocalSearchBeam(setup, nick, _beamsize, _neighbors); arglist.Enqueue(resname); }); // actionlist.Add (() => { // var resname = Indexes.ExecuteLocalSearchMontecarloBeam(setup, nick, _beamsize, _neighbors); // arglist.Enqueue(resname); // }); } } foreach (var numInstances in setup.LSHFloatVector_INDEXES) { foreach (var numSamples in setup.LSHFloatVector_SAMPLES) { var _numInstances = numInstances; var _numSamples = numSamples; actionlist.Add (() => { var resname = Indexes.ExecuteLSHFloatVector (setup, nick, _numInstances, _numSamples); arglist.Enqueue(resname); }); } } if (setup.SPAWN == 1) { foreach (var action in actionlist) { action.Invoke (); } } else { LongParallel.ForEach (actionlist, (a) => a.Invoke (), setup.SPAWN); } if (setup.ExecuteSearch) { Commands.Check (arglist); } }
public CachePrinter(IPrinterChange ipc) { m_IPrinterChange = ipc; _cachList = new ConcurrentQueue <MyStruct>(); _bReadExited = false; }