BackgroundWorker Mono GTK# Monodevelop .NET

08:03:2013 г.

BackgroundWorker GTK# Mono .NET. , , , . .

, , Thread . . Mono .NET, , IAsyncResult. GTK#.

. , BackgroundWorker - BackgroundWorker.cs:

using System;
using Gtk;
using System.Threading;

namespace X
{
    public abstract class BackgroundWorker
    {
        protected object result;
        protectedThreadNotify completed;
        protectedThread asyncThread;

        public BackgroundWorker ()
        {
           result = null;
           completed = newThreadNotify (newReadyEvent (ready));
           asyncThread = newThread(newParameterizedThreadStart(DoWork));
        }

        protected abstract void DoWork(object param = null);

        public void RunWorkerAsync(object param = null)
        {
           asyncThread.Start(param);
        }

        protected virtual void ready(){}
    }
}

- , , .

- DoWork, RunWorkerAsync . object, .. . - completed.WakeupMain(); , , , ready Mono.

, ready virtual . RunWorkerAsync , DoWork .

, Mono .NET GTK#. , .

private classDBChecker :BackgroundWorker
{
    protected override void DoWork(object param)
    {
        result = false;

        if(param != null)
        {
            MySqlConnection dbcon;
            dbcon = newMySqlConnection(param.ToString());
            try
            {
                dbcon.Open();
                result = true;
            }
            catch { }
        }
      completed.WakeupMain();
    }

    protected override void ready()
    {
       if(this.result == null)
          return;
       if(!(this.result is bool))
          return;
       if(bool.Parse(this.result.ToString()) == true)
           MessageBox.Show(" ");
       else
           MessageBox.Show(" ");
    }
}

result - , , completed.WakeupMain() .

:

DBChecker checker = newDBChecker();
checker.RunWorkerAsync(_connectionString);

, . . Mono BackgroundWorker Windows Forms C#.

P.S: - , , - . .

 





« TextBox Entry enabled = false GTK# Mono .Net Mono MySQL .NET »

fotic.jpg