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. WPF
  4. GUI updations on socket callback

GUI updations on socket callback

Scheduled Pinned Locked Moved WPF
questionannouncement
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.
  • J Offline
    J Offline
    JS 2008
    wrote on last edited by
    #1

    I have a silverlight application,that communicating and getting data through socket communication.At each Receive callback i want to get data and update in the GUI at the moment itself.In this case sending and receiving data asynchronously,but the delegate for GUI updation in action only after all receive callbacks.How can i execute GUI updations sequentially with each callback?

    M 1 Reply Last reply
    0
    • J JS 2008

      I have a silverlight application,that communicating and getting data through socket communication.At each Receive callback i want to get data and update in the GUI at the moment itself.In this case sending and receiving data asynchronously,but the delegate for GUI updation in action only after all receive callbacks.How can i execute GUI updations sequentially with each callback?

      M Offline
      M Offline
      Michael Sync
      wrote on last edited by
      #2

      You can call another service after completing of first call. For example: service.Call1Completed += (sender, e) => { //Update the UI. service.Call2Completed += (srd,e1) => { //Update the UI. }; service.Call2Async(); }; service.Call1Async();

      Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) Microsoft MVP (Silverlight), WPF/Silverlight Insiders

      J 1 Reply Last reply
      0
      • M Michael Sync

        You can call another service after completing of first call. For example: service.Call1Completed += (sender, e) => { //Update the UI. service.Call2Completed += (srd,e1) => { //Update the UI. }; service.Call2Async(); }; service.Call1Async();

        Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) Microsoft MVP (Silverlight), WPF/Silverlight Insiders

        J Offline
        J Offline
        JS 2008
        wrote on last edited by
        #3

        My scenario is like this. SocketReceiveCallback(object sender, SocketAsyncEventArgs e ) { // read data from e.Buffer. if ( dataReceived == TotalDataSize ) // checks of the complete reception of one image { // update the GUI using the received data. System.Diagnostics.Debug.WriteLine( “ received image “ ); Dispatcher.BeginInvoke(new DisplayImageDelgate(DislayImageData), imageData); // imageData is a class containing the received data } Else { // call socket.receiveAsync() to get next set of data. } } private void DisplayImageData (MyImageData data) { if (data.ImageStream != null) { BitmapImage bmp = new BitmapImage(); bmp.SetSource(new MemoryStream(data.ImageStream)); myReceivedImageCtrl.Source = bmp; //GUI update should happen at this point. System.Diagnostics.Debug.WriteLine( “ Draw image “ ); } } Please note that my application, there is continues async requests to server ( corresponding to user action ) and server responds with a stream of image data( eg:- 100 images. The application needs to update the GUI immediately after each image is received ( even while the server streams the data). In the above case although the SocketReceiveCallback is getting the data continuously from server, the GUI update happens only after all the data receive is completed( which can take a long time ). It seems that although the DisplayImage function is invoked using BeginInvoke, the system actually executes the display function at a later stage, causing ‘jumping’ image displays The debug trace obtained was:- received image received image received image received image Draw image Draw image Draw image Instead of the needed received image Draw image received image Draw image received image Draw image What could be done? Thanks and Regards JS

        M 1 Reply Last reply
        0
        • J JS 2008

          My scenario is like this. SocketReceiveCallback(object sender, SocketAsyncEventArgs e ) { // read data from e.Buffer. if ( dataReceived == TotalDataSize ) // checks of the complete reception of one image { // update the GUI using the received data. System.Diagnostics.Debug.WriteLine( “ received image “ ); Dispatcher.BeginInvoke(new DisplayImageDelgate(DislayImageData), imageData); // imageData is a class containing the received data } Else { // call socket.receiveAsync() to get next set of data. } } private void DisplayImageData (MyImageData data) { if (data.ImageStream != null) { BitmapImage bmp = new BitmapImage(); bmp.SetSource(new MemoryStream(data.ImageStream)); myReceivedImageCtrl.Source = bmp; //GUI update should happen at this point. System.Diagnostics.Debug.WriteLine( “ Draw image “ ); } } Please note that my application, there is continues async requests to server ( corresponding to user action ) and server responds with a stream of image data( eg:- 100 images. The application needs to update the GUI immediately after each image is received ( even while the server streams the data). In the above case although the SocketReceiveCallback is getting the data continuously from server, the GUI update happens only after all the data receive is completed( which can take a long time ). It seems that although the DisplayImage function is invoked using BeginInvoke, the system actually executes the display function at a later stage, causing ‘jumping’ image displays The debug trace obtained was:- received image received image received image received image Draw image Draw image Draw image Instead of the needed received image Draw image received image Draw image received image Draw image What could be done? Thanks and Regards JS

          M Offline
          M Offline
          Michael Sync
          wrote on last edited by
          #4

          You can create one List and add the image data on completed event. and call the draw before receiving all data.

          Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) Microsoft MVP (Silverlight), WPF/Silverlight Insiders

          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