Example #1
0
        /// <summary>
        /// Ýþ parçasýný kuyruða sokar.
        /// </summary>
        /// <param name="workItem">Ýþ parçasý.</param>
        public void QueueWorkItem(IWorkItem workItem)
        {
            if (workItem == null)
            {
                throw new ArgumentNullException("workItem");
            }

            if (m_IsShuttingdown)
            {
                throw new LaboThreadingException("Ýþçi thread havuzu kapatýlýyor. Yeni iþ parçasý ekleyemezsiniz.");
            }

            lock (m_WorkItemQueue)
            {
                // Ýþ parçasýnýn kuyruða atýlmadan önceki ilk durumu: "Yaratýldý".
                workItem.State = WorkItemState.Created;

                OnWorkerThreadPoolEnqueuingNewWorkItem(new WorkerThreadPoolEnqueuingNewWorkItemEventArgs(workItem));

                m_WorkItemQueue.Enqueue(workItem);

                IncrementWorkItemsCount();

                OnWorkerThreadPoolEnqueuedNewWorkItem(new WorkerThreadPoolEnqueuedNewWorkItemEventArgs(workItem));

                // Eðer kuyrukta bekleyen ve iþlenen iþ parçasý sayýsý toplamý iþçi thread sayýsýndan fazla ise
                // yeni iþçi thread yaratmaya çalýþýyoruz.
                if (m_CurrentWorkItemsCount > m_WorkerThreads.Count)
                {
                    TryStartNewThreads(1);
                }
            }
        }
Example #2
0
        private void SendEmailAsync(Context context, DayOverview dayOverview)
        {
            m_workItemQueue.Enqueue(async cancellationToken =>
            {
                cancellationToken.ThrowIfCancellationRequested();

                var email = await m_amazonService.GetEmailAsync(context).ConfigureAwait(false);
                if (email == null)
                {
                    return;
                }

                cancellationToken.ThrowIfCancellationRequested();

                try
                {
                    var subject  = $"Übersicht {dayOverview.Cinema.Name}";
                    var htmlBody = m_dayOverviewEmailFormatter.Format(dayOverview);
                    if (string.IsNullOrEmpty(htmlBody))
                    {
                        return;
                    }

                    await m_emailService.SendEmailOverviewAsync(email, subject, htmlBody).ConfigureAwait(false);
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                }
            });
        }
        /// <summary>
        /// Adds the request to build a texture for the specified planet onto a build queue
        /// </summary>
        public void QueueBuild( IWorkItemQueue queue, ISpherePlanet planet, Action<ITexture> onComplete )
        {
            SourceSinkWorkItem.Builder<Bitmap[]> sourceSink = new SourceSinkWorkItem.Builder<Bitmap[]>( );
            sourceSink.SetSource( CreateTextureBitmaps, planet );
            sourceSink.SetSink( FinishBuild, onComplete );

            queue.Enqueue( sourceSink.Build( "Build Marble Texture" ), null );
        }
 public void Enqueue(Func <CancellationToken, Task> workItem)
 {
     m_workItemQueue.Enqueue(workItem);
 }