Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Problem with Event and Timer

Problem with Event and Timer

Scheduled Pinned Locked Moved C#
helpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Leon van Wyk
    wrote on last edited by
    #1

    I developed a SMS application, I use a timer to pool the modem every now and then for new responses if a response is found I launch an ResponseReceived event, then that event looks for the type of response, then when a new message is detected I launch the NewMessageReceived event from the ResponseReceived event. The main application receives this event and opens a new dialog window, but the problem is that it does not show the window. I can see the window in the taskbar but not on the screen. I tried forcing the window to show, go topmost, maximize, every thing, but no window. I suspect that this could be due to threading of the timer or something, can anyone help? Leon v Wyk

    D 1 Reply Last reply
    0
    • L Leon van Wyk

      I developed a SMS application, I use a timer to pool the modem every now and then for new responses if a response is found I launch an ResponseReceived event, then that event looks for the type of response, then when a new message is detected I launch the NewMessageReceived event from the ResponseReceived event. The main application receives this event and opens a new dialog window, but the problem is that it does not show the window. I can see the window in the taskbar but not on the screen. I tried forcing the window to show, go topmost, maximize, every thing, but no window. I suspect that this could be due to threading of the timer or something, can anyone help? Leon v Wyk

      D Offline
      D Offline
      Daniel Turini
      wrote on last edited by
      #2

      Leon v Wyk wrote: I suspect that this could be due to threading of the timer or something, can anyone help? You're right: see the docs for the InvokeRequired property, and you'll understand more. Simply put, you can only do UI tasks on the main thread. There's an "Invoke" method and an "InvokeRequired" property on all controls and forms that ease things for you. Yes, even I am blogging now!

      L 1 Reply Last reply
      0
      • D Daniel Turini

        Leon v Wyk wrote: I suspect that this could be due to threading of the timer or something, can anyone help? You're right: see the docs for the InvokeRequired property, and you'll understand more. Simply put, you can only do UI tasks on the main thread. There's an "Invoke" method and an "InvokeRequired" property on all controls and forms that ease things for you. Yes, even I am blogging now!

        L Offline
        L Offline
        Leon van Wyk
        wrote on last edited by
        #3

        Thank you so much! How do I send variables to the method that I invoke? private delegate void NewSMSReceived(); protected void OnNewSMSReceived() { int Position = 1; Solutions.Gsm.Modem.SMSMessageReceive SMS = Gsm.ReadSms(Position,true); SMSReceivedForm NewSMS = new SMSReceivedForm(SMS); NewSMS.ShowDialog(); } private void Gsm_NewSMSReceived(object sender, Being.IT.Solutions.Gsm.Modem.NewSMSEventArgs e) { lbInfo.Text = "New SMS received @ "+ DateTime.Now.ToString(); Solutions.Multimedia.SoundPlayer.Play(Application.StartupPath+@"\NewSMSNotify.wav"); //e.StoragePosistion this.BeginInvoke( new NewSMSReceived( this.OnNewSMSReceived) ); } Leon v Wyk

        D 1 Reply Last reply
        0
        • L Leon van Wyk

          Thank you so much! How do I send variables to the method that I invoke? private delegate void NewSMSReceived(); protected void OnNewSMSReceived() { int Position = 1; Solutions.Gsm.Modem.SMSMessageReceive SMS = Gsm.ReadSms(Position,true); SMSReceivedForm NewSMS = new SMSReceivedForm(SMS); NewSMS.ShowDialog(); } private void Gsm_NewSMSReceived(object sender, Being.IT.Solutions.Gsm.Modem.NewSMSEventArgs e) { lbInfo.Text = "New SMS received @ "+ DateTime.Now.ToString(); Solutions.Multimedia.SoundPlayer.Play(Application.StartupPath+@"\NewSMSNotify.wav"); //e.StoragePosistion this.BeginInvoke( new NewSMSReceived( this.OnNewSMSReceived) ); } Leon v Wyk

          D Offline
          D Offline
          Daniel Turini
          wrote on last edited by
          #4

          Leon v Wyk wrote: //e.StoragePosistion this.BeginInvoke( new NewSMSReceived( this.OnNewSMSReceived) ); This becomes (I removed all the 'this.', I find it weird): Invoke(new MethodInvoker(OnNewSMSReceived), new object[] { your variables go here }); Other alternative would be using properties, since you're on different threads, but will be invoking methods on the same object ('this.'). Yes, even I am blogging now!

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups