[Gtk-sharp-list] GLib.Timerout How to use?

True Friend true.friend2004 at gmail.com
Sun Sep 14 04:37:05 EDT 2008


Thanks a lot. It is working fine now. I used this code on windows and was
trying to search something like it on mono as well.
----------------------------------------------
void ToolStripMenuItemAutoSaveClick(object sender, EventArgs e)
        {
            ToolStripMenuItem item = (ToolStripMenuItem)sender;
            if(item.Checked == true)
            {
            timer = new Timer();
            timer.Interval = 6000;
            timer.Start();
            timer.Tick += AutoSaveEventHandler;
            }
            else
            {
                timer.Stop();
            }
        }
        //auto save event handler
        void AutoSaveEventHandler(object sender, EventArgs e)
        {
            if(Form1.textFilePath != null)
            {
                if(pattern.IsMatch(textFilePath) == true)
                {
                    string f = File.ReadAllText(textFilePath);
                    string pathg = textFilePath + "~";
                    File.WriteAllText(pathg, f);
                    urduRichTextBox1.SaveFile(textFilePath,
RichTextBoxStreamType.RichText);
                }
                else{
                    string f = File.ReadAllText(textFilePath);
                    string pathg = textFilePath + "~";
                    File.WriteAllText(pathg, f);
                urduRichTextBox1.SaveFile(textFilePath,
RichTextBoxStreamType.UnicodePlainText);
                }
            }
----------------------------------------------------
You can see there is no separate thread involved here, System.Timers.Timer
class is working fine. I tried to use this class but the event Timer.Tick
wasn't available and when I tried to use Timer.Elapsed event.
-----------------------------------------------------
if(Action4.Active == true)
            {

            if(textFilePath == null)
            {
                OnSaveActionActivated(sender, e);
            }
            timer = new Timer();
            timer.Interval = 300;
            timer.Start();
            timer.Elapsed += AutoSaveEventHandler;
            }
            else
            {
                timer.Stop();
            }
------------------------------------------
It was pretty much straight forward but I couldn't get it work on mono, it
also frozen the GUI. Can you tell me whats wrong with this code?
Regards

-- 
Muhammad Shakir Aziz محمد شاکر عزیز
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/gtk-sharp-list/attachments/20080914/20d3c2f6/attachment-0001.html 


More information about the Gtk-sharp-list mailing list