Ejemplo n.º 1
0
 public IrcClient(string Server, int Port, string ServerPassword)
 {
     ops = AsyncOperationManager.CreateOperation(null);
     _server = Server;
     _port = Port;
     _serverPass = ServerPassword;
 }
Ejemplo n.º 2
0
 public IrcClient(string Server)
     : this(Server, 6667)
 {
     ops = AsyncOperationManager.CreateOperation(null);
     _server = Server;
     _port = 6667;
 }
Ejemplo n.º 3
0
        public void CalculateAsync()
        {
            if (task_id != Guid.Empty)
            {
                throw new InvalidOperationException();
            }

            task_id = Guid.NewGuid();
            async_operation = AsyncOperationManager.CreateOperation(task_id);
            Action calc = () =>
            {
                Exception error = null;
                try
                {
                    CalculatePrimeNumbers();
                }
                catch (Exception ex)
                {
                    error = ex;
                }
                bool cancelled = IsTaskCanceled;
                bool lock_taken = false;
                spin_lock_task_id.Enter(ref lock_taken);
                task_id = Guid.Empty;
                spin_lock_task_id.Exit(false);
                async_operation.PostOperationCompleted((arg) =>
                {
                    if (CalculateCompleted != null)
                    {
                        CalculateCompleted(this, arg as AsyncCompletedEventArgs);
                    }
                }, new AsyncCompletedEventArgs(error, cancelled, async_operation.UserSuppliedState));
            };
            this.AsyncResult = calc.BeginInvoke(null, null);
        }
Ejemplo n.º 4
0
        public void Dispose()
        {
            IDisposable disposable = _fx as IDisposable;
            if (disposable != null)
                disposable.Dispose();

            _asyncOp = null;
        }
Ejemplo n.º 5
0
		public MessageMarkService([NotNull] IServiceProvider provider)
		{
			if (provider == null)
				throw new ArgumentNullException(nameof(provider));

			_provider = provider;
			_uiAsyncOperation = _provider.GetRequiredService<IUIShell>().CreateUIAsyncOperation();
		}
Ejemplo n.º 6
0
 public void Run2()
 {
     somethingHappened += SynchronizationDemo_somethingHappened;
     operation = AsyncOperationManager.CreateOperation(null);
     Thread workerThread = new Thread(new ThreadStart(DoWork));
     workerThread.Start();
     Thread.Sleep(2000);
     Output("Call end");
 }
Ejemplo n.º 7
0
        private void loading(object obj, AsyncOperation asyncOperation)
        {
            string[] flist = (string[])obj;

            //loading
            string res = "ok";

            asyncOperation.PostOperationCompleted(new SendOrPostCallback(OnComplete), res);
        }
Ejemplo n.º 8
0
		public UIShell(Func<IWin32Window> parentWindowGetter, [NotNull] Action<bool> uiFreezer)
		{
			if (parentWindowGetter == null)
				throw new ArgumentNullException(nameof(parentWindowGetter));
			if (uiFreezer == null) throw new ArgumentNullException(nameof(uiFreezer));
			_parentWindowGetter = parentWindowGetter;
			_uiFreezer = uiFreezer;
			_ctorAsyncOperation = AsyncHelper.CreateOperation();
		}
Ejemplo n.º 9
0
        public GemixCompiler()
        {
            _Thread = new Thread(new ParameterizedThreadStart(gemix_compiler));
            _Thread.Priority = ThreadPriority.Normal;
            _Thread.IsBackground = true;

            _OutputCallBack = new SendOrPostCallback(OutputCallBack);

            _AsyncOperation = AsyncOperationManager.CreateOperation(null);
        }
        protected void LongOperation_Completed(object sender, LongOperationCompletedEventArgs e) {
            progressControl.Dispose();
            progressControl = null;
            ((DevExpress.ExpressApp.Demos.LongOperation)sender).CancellingTimeoutExpired -= LongOperation_CancellingTimeoutExpired;
            ((DevExpress.ExpressApp.Demos.LongOperation)sender).Completed -= LongOperation_Completed;
            ((DevExpress.ExpressApp.Demos.LongOperation)sender).Dispose();

            waitLongOperationCompleted.PostOperationCompleted(WorkCompleted, null);
            waitLongOperationCompleted = null;
        }
 /// <summary>
 /// 初始化CommentInput类的新实例。
 /// </summary>
 protected CommentInput()
 {
     operation = AsyncOperationManager.CreateOperation(Guid.NewGuid());
     onComment = new SendOrPostCallback(o =>
         {
             if (Comment != null)
                 Comment(this, new CommentEventArgs((string)o));
         }
     );
 }
 public SyncGroupHelper(string groupName, object userState, AsyncOperation asyncOp, SendOrPostCallback progressReporterDelegate)
 {
     if (groupName == null)
     {
         throw new ArgumentNullException("groupName");
     }
     this.groupName = groupName;
     this.userState = userState;
     this.asyncOperation = asyncOp;
     this.progressReporter = progressReporterDelegate;
 }
Ejemplo n.º 13
0
		public ProgressForm(IServiceProvider provider)
		{
			if (provider == null)
				throw new ArgumentNullException(nameof(provider));

			_serviceProvider = provider;

			_asyncOp = AsyncHelper.CreateOperation();

			InitializeComponent();
		}
Ejemplo n.º 14
0
        internal Navigator([NotNull] IServiceProvider serviceProvider)
        {
            if (serviceProvider == null)
                throw new ArgumentNullException("serviceProvider");

            _serviceProvider = serviceProvider;

            _uiAsyncOperation = _serviceProvider.GetRequiredService<IUIShell>().CreateUIAsyncOperation();
            _form = new NavigationDummyForm(_serviceProvider);
            _serviceProvider.GetRequiredService<DockManager>().RegisterPersistablePane(_form);
        }
Ejemplo n.º 15
0
 public AsyncGuessState(
     string phrase,
     NetworkSetting networkSetting,
     AsyncOperation asyncOperation,
     EventHandler<GuessCompletedEventArgs> guessCompletedHandler)
 {
     this.asyncOperation = asyncOperation;
     this.phrase = phrase;
     this.networkSetting = networkSetting;
     GuessCompleted += guessCompletedHandler;
 }
Ejemplo n.º 16
0
        private void CompletionMethod(string output, Exception ex, bool cancelled, AsyncOperation asyncOp)
        {
            lock (userStateDictionary)
            {
                userStateDictionary.Remove(asyncOp.UserSuppliedState);
            }

            // results of the operation
            asyncOp.PostOperationCompleted(onCompletedDelegate,
                new LongTaskCompletedEventArgs(output, ex, cancelled, asyncOp.UserSuppliedState));
        }
Ejemplo n.º 17
0
 protected override Bitmap Process(Bitmap bitmap, AsyncOperation asyncOp)
 {
     Bitmap newBitmap = new Bitmap(bitmap);
     Graphics g = Graphics.FromImage(newBitmap);
     g.SmoothingMode = SmoothingMode.HighQuality;
     g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
     SizeF textSize = g.MeasureString(ImageAddTextPluginContext.Text, ImageAddTextPluginContext.Font);
     PointF p = new Point();
     switch (ImageAddTextPluginContext.Position)
     {
         case ContentAlignment.TopLeft:
             p.X = 0.0f;
             p.Y = 0.0f;
             break;
         case ContentAlignment.TopCenter:
             p.X = (newBitmap.Width - textSize.Width) / 2;
             p.Y = 0.0f;
             break;
         case ContentAlignment.TopRight:
             p.X = newBitmap.Width - textSize.Width;
             p.Y = 0.0f;
             break;
         case ContentAlignment.MiddleLeft:
             p.X = 0.0f;
             p.Y = (newBitmap.Height - textSize.Height) / 2;
             break;
         case ContentAlignment.MiddleCenter:
             p.X = (newBitmap.Width - textSize.Width) / 2;
             p.Y = (newBitmap.Height - textSize.Height) / 2;
             break;
         case ContentAlignment.MiddleRight:
             p.X = newBitmap.Width - textSize.Width;
             p.Y = (newBitmap.Height - textSize.Height) / 2;
             break;
         case ContentAlignment.BottomLeft:
             p.X = 0.0f;
             p.Y = newBitmap.Height - textSize.Height;
             break;
         case ContentAlignment.BottomCenter:
             p.X = (newBitmap.Width - textSize.Width) / 2;
             p.Y = newBitmap.Height - textSize.Height;
             break;
         case ContentAlignment.BottomRight:
             p.X = newBitmap.Width - textSize.Width;
             p.Y = newBitmap.Height - textSize.Height;
             break;
     }
     p.X += ImageAddTextPluginContext.XOffset;
     p.Y += ImageAddTextPluginContext.YOffset;
     g.DrawString(ImageAddTextPluginContext.Text, ImageAddTextPluginContext.Font, new SolidBrush(ImageAddTextPluginContext.Color), p);
     g.Dispose();
     return newBitmap;
 }
Ejemplo n.º 18
0
 private void DispatchCompleting(MessageData responsemsg, Exception ex, bool canceled, AsyncOperation asyncOper)
 {
     if (!canceled)
     {
         lock (_userStateToLifetime.SyncRoot)
         {
             _userStateToLifetime.Remove(asyncOper.UserSuppliedState);
         }
     }
     TransmitCompletedEventArgs eventArgs = new TransmitCompletedEventArgs(responsemsg, ex, canceled, asyncOper.UserSuppliedState);
     asyncOper.PostOperationCompleted(onCompletedDelegate, eventArgs);
 }
		public void TestInit()
		{
			ManualResetEvent waitHandle = new ManualResetEvent(false);
			ThreadPool.QueueUserWorkItem(o =>
			{
				operation = AsyncOperationManager.CreateOperation(null);
				InputProviderManager = new InputProviderManager_Accessor(new Provider());
				waitHandle.Set();
				Application.Run();
			});
			waitHandle.WaitOne();
		}
 /// <summary>
 /// Calls constructor for the downloader object
 /// </summary>
 /// <param name="url">URL of the source</param>
 /// <param name="finalPath">Final save path to merge all partial files downloaded</param>
 /// <param name="rangeDir">Temporary save path for partial downloads</param>
 /// <param name="nofThread">Number of async threads to download with</param>
 public HttpMultiThreadDownloader(string url, string saveDir, string saveFileName, string rangeDir, int nofThread)
 {
     new GlobalLock();
     HttpGlobalSettings.Set();
     Url              = url;
     RangeDir         = rangeDir;
     SaveDir          = saveDir;
     NofThread        = nofThread;
     SaveFileName     = saveFileName;
     stopTimer.Tick  += stopTimer_Tick;
     aop              = SC.AsyncOperationManager.CreateOperation(null);
     speedBytesOffset = 0;
 }
Ejemplo n.º 21
0
        private void IndexerThread(AsyncOperation operation, bool isCreateNewDbFile)
        {
            for (int i = 0; i < 100000; i++)
            {

            }

            SendOrPostCallback callUpdate = delegate(object o)
                                                {
                                                    _view.CloseView();
                                                };
            operation.Post(callUpdate, null); ;
        }
Ejemplo n.º 22
0
 public void SortAsync(int[] data)
 {
     if (IsTaskCanceled)
     {
         task_id = Guid.NewGuid();
         sort_async_operation = AsyncOperationManager.CreateOperation(task_id);
         sort_delegate.BeginInvoke(data, null, null);
     }
     else
     {
         throw new InvalidOperationException();
     }
 }
        protected void StartLongOperation(List<string> strings) {

            waitLongOperationCompleted = AsyncOperationManager.CreateOperation(null);
            var longOperation = new DevExpress.ExpressApp.Demos.LongOperation(DoWork) { CancellingTimeoutMilliSeconds = 2000 };
            longOperation.CancellingTimeoutExpired += LongOperation_CancellingTimeoutExpired;
            longOperation.Completed += LongOperation_Completed;

            ChangedProps = strings;
            progressControl = CreateProgressControl();
            progressControl.ShowProgress(longOperation);
            longOperation.StartAsync();
            OnOperationStarted();
        }
Ejemplo n.º 24
0
        private void InvokeOperationCompeted(AsyncOperation asyncOp, SendOrPostCallback callback, UploadFileCompletedEventArgs eventArgs)
        {
            if (this.m_IsExpired)
                eventArgs = new UploadFileCompletedEventArgs("", new Exception(Properties.Settings.Default.UploadExpired), false, this.m_AsyncOperation.UserSuppliedState);

            if (Interlocked.CompareExchange<AsyncOperation>(ref this.m_AsyncOperation, null, asyncOp) == asyncOp)
            {
                var _originalWebResponse = Interlocked.Exchange<WebResponse>(ref this.m_WebResponse, null);
                closeResponse(_originalWebResponse);
                this.completeUploadClientState();
                asyncOp.PostOperationCompleted(callback, eventArgs);
            }
        }
Ejemplo n.º 25
0
 protected override Bitmap Process(Bitmap bitmap, AsyncOperation asyncOp)
 {
     Bitmap newBitmap = new Bitmap(bitmap.Width, bitmap.Height);
     Graphics graphics = Graphics.FromImage(newBitmap);
     for (int y = 0; y < bitmap.Height; y += Size)
     {
         for (int x = 0; x < bitmap.Width; x += Size)
         {
             int a = 0, r = 0, g = 0, b = 0;
             int yb = y + Size;
             int xb = x + Size;
             for (int yt = y; yt < yb && yt < bitmap.Height; yt++)
             {
                 for (int xt = x; xt < xb && xt < bitmap.Width; xt++)
                 {
                     Color color = bitmap.GetPixel(xt, yt);
                     a += color.A;
                     r += color.R;
                     g += color.G;
                     b += color.B;
                 }
             }
             int wt, ht;
             if (x + Size > bitmap.Width)
             {
                 wt = bitmap.Width - x;
             }
             else
             {
                 wt = Size;
             }
             if (y + Size > bitmap.Height)
             {
                 ht = bitmap.Height - y;
             }
             else
             {
                 ht = Size;
             }
             double nt = wt * ht;
             Color newColor = Color.FromArgb((int)Math.Round(a / nt), (int)Math.Round(r / nt), (int)Math.Round(g / nt), (int)Math.Round(b / nt));
             graphics.FillRectangle(new SolidBrush(newColor), x, y, wt, ht);
         }
         if (y + Size < bitmap.Height)
         {
             this.DoProcessAsyncProgressChanged(asyncOp, new ProgressChangedEventArgs((int)Math.Round(100.0 * (y + Size) / bitmap.Height), asyncOp.UserSuppliedState));
         }
     }
     graphics.Dispose();
     return newBitmap;
 }
Ejemplo n.º 26
0
        public void DownloadAsync()
        {
            currentAsycLoadOperation = AsyncOperationManager.CreateOperation(null);
            if (loadCompletedDelegate == null)
            {
                loadCompletedDelegate = new SendOrPostCallback(LoadCompletedDelegate);
                loadProgressDelegate = new SendOrPostCallback(LoadProgressDelegate);
                readBuffer = new byte[readBlockSize];
            }
            tempDownloadStream = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write);

            WebRequest req = WebRequest.Create(url);
            (new WaitCallback(BeginGetResponseDelegate)).BeginInvoke(req, null, null);
        }
Ejemplo n.º 27
0
        public void CrawlAsync(ICrawlDaddy crawl)
        {
            // Create an AsyncOperation for taskId.
            _asyncOp = AsyncOperationManager.CreateOperation(crawl.CrawlerId);

            crawl.DomainCrawlStarted += crawl_DomainCrawlStarted;
            crawl.DomainCrawlEnded += crawl_DomainCrawlEnded;
            crawl.LinkCrawlCompleted += crawl_LinkCrawlCompleted;
            crawl.ExternalLinksFound += crawl_ExternalLinksFound;

            // Start the asynchronous operation.
            WorkerEventHandler workerDelegate = new WorkerEventHandler(CrawlWorker);
            workerDelegate.BeginInvoke(crawl, _asyncOp, null, null);
        }
Ejemplo n.º 28
0
 protected override Bitmap Process(Bitmap bitmap, AsyncOperation asyncOp)
 {
     Bitmap newBitmap = new Bitmap(ImageCutPluginContext.Size.Width, ImageCutPluginContext.Size.Height);
     newBitmap.SetResolution(bitmap.HorizontalResolution, bitmap.VerticalResolution);
     Graphics g = Graphics.FromImage(newBitmap);
     g.Clear(ImageCutPluginContext.FillColor);
     Point p = new Point();
     switch (ImageCutPluginContext.Position)
     {
         case ContentAlignment.TopLeft:
             p.X = 0;
             p.Y = 0;
             break;
         case ContentAlignment.TopCenter:
             p.X = (int)Math.Round((newBitmap.Width - bitmap.Width) / 2.0);
             p.Y = 0;
             break;
         case ContentAlignment.TopRight:
             p.X = newBitmap.Width - bitmap.Width;
             p.Y = 0;
             break;
         case ContentAlignment.MiddleLeft:
             p.X = 0;
             p.Y = (int)Math.Round((newBitmap.Height - bitmap.Height) / 2.0);
             break;
         case ContentAlignment.MiddleCenter:
             p.X = (int)Math.Round((newBitmap.Width - bitmap.Width) / 2.0);
             p.Y = (int)Math.Round((newBitmap.Height - bitmap.Height) / 2.0);
             break;
         case ContentAlignment.MiddleRight:
             p.X = newBitmap.Width - bitmap.Width;
             p.Y = (int)Math.Round((newBitmap.Height - bitmap.Height) / 2.0);
             break;
         case ContentAlignment.BottomLeft:
             p.X = 0;
             p.Y = newBitmap.Height - bitmap.Height;
             break;
         case ContentAlignment.BottomCenter:
             p.X = (int)Math.Round((newBitmap.Width - bitmap.Width) / 2.0);
             p.Y = newBitmap.Height - bitmap.Height;
             break;
         case ContentAlignment.BottomRight:
             p.X = newBitmap.Width - bitmap.Width;
             p.Y = newBitmap.Height - bitmap.Height;
             break;
     }
     g.DrawImage(bitmap, p);
     g.Dispose();
     return newBitmap;
 }
Ejemplo n.º 29
0
        private void DoLongTask(string input, AsyncOperation asyncOp)
        {
            Exception e = null;
            string output = null;
            try
            {
                output = LongTask(input);
            }
            catch (Exception ex)
            {
                e = ex;
            }
            this.CompletionMethod(output, e, false, asyncOp);

        }
Ejemplo n.º 30
0
 public void RunAsync(System.ComponentModel.AsyncOperation syncContext)
 {
     if (!IsBusy)
     {
         this._asyncOperation = syncContext;
         //we pass the worker thread back to this calling thread so we can call abort on it
         Action action = () => { this._workerThread = Thread.CurrentThread; this.RunThis(); };
         this.IsBusy = true;
         this.Status = BatchJobStatus.Busy;
         action.BeginInvoke(this.RunJobAsyncCallback, action);
     }
     else
     {
         EmitException(new InvalidOperationException("Job is already running!"));
     }
 }
Ejemplo n.º 31
0
        public SearchDummyForm(IServiceProvider provider)
        {
            _asyncOperation = AsyncHelper.CreateOperation();
            _serviceManager = new ServiceManager(provider);

            _serviceManager.Publish<IDefaultCommandService>(
                new DefaultCommandService("Janus.Forum.GoToMessage"));

            this.AssignServices(provider);

            InitializeComponent();

            _msgViewer = new MsgViewer(_serviceManager) { Dock = DockStyle.Fill };
            _splitContainer.Panel2.Controls.Add(_msgViewer);
            CustomInitializeComponent();
        }
Ejemplo n.º 32
0
        protected virtual void DoWork(AsyncOperation asyncOp, params object[] arguments) 
        { 
            Exception error = null;

            if (!this.CancellationPending)
            {
                try
                {
                    this.DoWork(arguments);
                }
                catch (Exception e)
                {
                    error = e;
                }
            }

            this.TriggerCompletionEvent(error, this.CancellationPending, this.asyncOperation);
        }
 internal AsyncOperationContext(System.ComponentModel.AsyncOperation asyncOperation, ClientBase <TChannel> .EndOperationDelegate endDelegate, SendOrPostCallback completionCallback)
 {
     this.asyncOperation     = asyncOperation;
     this.endDelegate        = endDelegate;
     this.completionCallback = completionCallback;
 }
Ejemplo n.º 34
0
        /// <summary>
        ///     Only for use by AsyncOperationManager to create new AsyncOperation objects
        /// </summary>
        internal static AsyncOperation CreateOperation(object userSuppliedState, SynchronizationContext syncContext)
        {
            AsyncOperation newOp = new AsyncOperation(userSuppliedState, syncContext);

            return(newOp);
        }
 public static AsyncOperation CreateOperation(object userSuppliedState)
 {
     return(AsyncOperation.CreateOperation(userSuppliedState, SynchronizationContext));
 }