Пример #1
0
        protected void btn_Continua_Click(object sender, EventArgs e)
        {
            //Andrea
            //Prelevo la descrizione e la passo come parametro del metodo importa
            string descrizione = this.descrizione.Text.ToString();

            mDelegate = new asyncDelegate(importa);
            AsyncCallback callback = new AsyncCallback(asyncImport);

            //Andrea
            //Aggiunta parametro descrizione
            mDelegate.BeginInvoke(UserManager.getInfoUtente(this), EsitoImport, descrizione, callback, null);

            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", "alert('Import inviato con successo!');", true);
            this.pnlReport.Visible   = false;
            this.btnNuovo.Enabled    = false;
            this.btnImporta.Enabled  = true;
            this.pnlAvviso.Visible   = false;
            this.pnlReport.Visible   = false;
            this.uploadFile.Disabled = false;
            this.uploadFile          = null;
            this.btnContinua.Enabled = false;
            this.box_upload.Update();
            this.upPnlReport.Update();

            this.descrizione.Text = string.Empty;
        }
Пример #2
0
        protected void BtnContinue_Click(object sender, EventArgs e)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "reallowOp", "reallowOp();", true);

            string descrizione = this.txtDescrizione.Text;

            mDelegate = new asyncDelegate(importa);
            AsyncCallback callback = new AsyncCallback(asyncImport);

            mDelegate.BeginInvoke(UserManager.GetInfoUser(), EsitoImport, descrizione, callback, null);

            ScriptManager.RegisterStartupScript(this, this.GetType(), "ajaxDialogModal", "ajaxDialogModal('InfoImportPreviousSendSuccesfully', 'info', '');", true);
            this.pnlReport.Visible   = false;
            this.BtnNew.Enabled      = false;
            this.BtnImport.Enabled   = true;
            this.pnlAvviso.Visible   = false;
            this.pnlReport.Visible   = false;
            this.fileUpload.Disabled = false;
            this.fileUpload          = null;
            this.BtnContinue.Enabled = false;
            this.box_upload.Update();
            this.upPnlReport.Update();

            this.txtDescrizione.Text = string.Empty;
        }
        public async Task taskStartAsyncDelegate(object sleepMS)
        {
            if (true)
            {
                await Task.Run(() =>
                {
                    AsyncMethodParameterObject asyncMethodParameterObject = new AsyncMethodParameterObject(sleepMS);
                    asyncDelegate asyncDelegateTask        = new asyncDelegate(asyncMethodTask);
                    AsyncCallback asyncCallback            = new AsyncCallback(callBackAsyncDelegate);
                    AsyncObjectStateClass asyncObjectState = new AsyncObjectStateClass(sleepMS);                                                //实例化类,该对象可以传入回调函数中
                    IAsyncResult iar = (AsyncResult)asyncDelegateTask.BeginInvoke(asyncMethodParameterObject, asyncCallback, asyncObjectState); //异步执行Method,界面不会假死,后执行回调函数,弹出提示框
                });
            }
            else   //lambda形式
            {
                await Task.Run(() =>
                {
                    //回调函数callback方法可以改写成lambda形式
                    //AsyncMethodParameterObject asyncMethodParameterObject = new AsyncMethodParameterObject(sleepMS);
                    new asyncDelegate(asyncMethodTask).BeginInvoke(new AsyncMethodParameterObject(sleepMS), ar =>
                    {   //回调函数写成了lambda形式
                        // Retrieve the delegate.
                        AsyncResult result   = (AsyncResult)ar;
                        asyncDelegate caller = (asyncDelegate)result.AsyncDelegate;

                        // Retrieve the format string that was passed as state information.
                        AsyncObjectStateClass asyncObjectState = (AsyncObjectStateClass)ar.AsyncState;//通过AsyncState获取传入的object

                        // Call EndInvoke to retrieve the results.
                        AsyncMethodReturnObject asyncMethodReturnObject = caller.EndInvoke(ar);

                        //MessageBox.Show(formatString.ToString() + "\n\r" + returnValue);
                    }, new AsyncObjectStateClass("Return String"));
                });
            }
        }