Click here to Skip to main content
15,887,454 members
Home / Discussions / C#
   

C#

 
AnswerRe: Get Picture Using PictureBox Handle Pin
User 740747021-Mar-16 8:43
User 740747021-Mar-16 8:43 
QuestionI want to generator serial numbers for rows in datagrid Pin
Engr. Yange21-Mar-16 3:06
Engr. Yange21-Mar-16 3:06 
AnswerRe: I want to generator serial numbers for rows in datagrid Pin
Eddy Vluggen22-Mar-16 7:17
professionalEddy Vluggen22-Mar-16 7:17 
QuestionUpdating the UI from a Rx background thread Pin
Kenneth Haugland20-Mar-16 23:38
mvaKenneth Haugland20-Mar-16 23:38 
AnswerRe: Updating the UI from a Rx background thread Pin
Luc Pattyn21-Mar-16 15:10
sitebuilderLuc Pattyn21-Mar-16 15:10 
GeneralRe: Updating the UI from a Rx background thread Pin
Kenneth Haugland21-Mar-16 19:16
mvaKenneth Haugland21-Mar-16 19:16 
GeneralRe: Updating the UI from a Rx background thread Pin
Luc Pattyn21-Mar-16 19:35
sitebuilderLuc Pattyn21-Mar-16 19:35 
GeneralRe: Updating the UI from a Rx background thread Pin
Kenneth Haugland21-Mar-16 20:24
mvaKenneth Haugland21-Mar-16 20:24 
Luc Pattyn wrote:
That article may be fine, it doesn't seem to focus on UI handling; for WinForms all Controls should be created and handled on exactly one thread, otherwise all anomalies are possible, and a temporary or permanent hangup is most likely to occur.

That is one of the selling points of using Rx, the ease of switching between the UI thread and a background thread to ensure that the UI is responsive.Take the following example (you need the rx-main and rx-xaml NuGet packages to run the code)
C#
var RxMouseMoveEvent = Observable.FromEventPattern<MouseEventArgs>(this, "MouseMove")
    .Select(arg=>arg.EventArgs.GetPosition(this));

RxMouseMoveEvent
    //Take it off the UI thread
    .ObserveOn(Scheduler.Default)
    // Wait for a 0.5 second pause
    .Throttle(new TimeSpan(0, 0, 0, 0, 500))
    //Do calcualtions with a function call that returns a point
    .Select(xy => CalculatePointRelateThing(xy))
    //Change it back to the UI thread
    .ObserveOnDispatcher()
    //Subscribe to the change on the UI thread
    .Subscribe(evt =>
    {
        txtText.Text = evt.ToString();
    });

The code does all calculation off the UI thread, so the UI doesn't hang up and remains responsive all the time. The problem was mixing this with the async Task calls seem to behave in a strange way.
Luc Pattyn wrote:
Maybe your attempt failed to correct all cross-thread violations, or OTOH your code could have a second problem on top of the UI threading one.

That might be the case, but right now I'm confused and don't even know where to look for my mistake. I basically want to start several async processes in the off UI thread. Each time an async prosses finishes I want a notification sent to the subscriber together with the result of the calculation. In addition to this, I wanted to know when all the started tasks were done, in order to display the results in an orderly fashion. After all the async processes could finish async Big Grin | :-D

I did manage to get it to work, but I felt that that was a dirty hack that I didn't like and was hoping to avoid using.
AnswerRe: Updating the UI from a Rx background thread Pin
Kenneth Haugland21-Mar-16 23:07
mvaKenneth Haugland21-Mar-16 23:07 
AnswerRe: Updating the UI from a Rx background thread Pin
Kenneth Haugland22-Mar-16 23:56
mvaKenneth Haugland22-Mar-16 23:56 
QuestionIntermittent problem with design-time display of inherited UserControls in VS 2013 Pin
BillWoodruff19-Mar-16 4:36
professionalBillWoodruff19-Mar-16 4:36 
AnswerRe: Intermittent problem with design-time display of inherited UserControls in VS 2013 Pin
OriginalGriff19-Mar-16 5:23
mveOriginalGriff19-Mar-16 5:23 
GeneralRe: Intermittent problem with design-time display of inherited UserControls in VS 2013 Pin
BillWoodruff19-Mar-16 8:30
professionalBillWoodruff19-Mar-16 8:30 
Questionproblem asked in SIEMENS. Pin
Member 1240313019-Mar-16 0:27
Member 1240313019-Mar-16 0:27 
GeneralRe: problem asked in SIEMENS. Pin
Sascha Lefèvre19-Mar-16 0:32
professionalSascha Lefèvre19-Mar-16 0:32 
AnswerRe: problem asked in SIEMENS. Pin
Richard MacCutchan19-Mar-16 0:37
mveRichard MacCutchan19-Mar-16 0:37 
AnswerRe: problem asked in SIEMENS. Pin
Patrice T19-Mar-16 12:05
mvePatrice T19-Mar-16 12:05 
Questionsorting records in datagrid Pin
Engr. Yange18-Mar-16 20:05
Engr. Yange18-Mar-16 20:05 
AnswerRe: sorting records in datagrid Pin
Mycroft Holmes18-Mar-16 21:43
professionalMycroft Holmes18-Mar-16 21:43 
QuestionIs there a better way in Rx? Pin
Matt T Heffron18-Mar-16 13:06
professionalMatt T Heffron18-Mar-16 13:06 
AnswerRe: Is there a better way in Rx? Pin
Kenneth Haugland18-Mar-16 16:02
mvaKenneth Haugland18-Mar-16 16:02 
AnswerRe: Is there a better way in Rx? Pin
Kenneth Haugland20-Mar-16 18:56
mvaKenneth Haugland20-Mar-16 18:56 
GeneralRe: Is there a better way in Rx? Pin
Matt T Heffron21-Mar-16 7:08
professionalMatt T Heffron21-Mar-16 7:08 
GeneralRe: Is there a better way in Rx? Pin
Kenneth Haugland21-Mar-16 7:47
mvaKenneth Haugland21-Mar-16 7:47 
GeneralRe: Is there a better way in Rx? Pin
Matt T Heffron21-Mar-16 9:53
professionalMatt T Heffron21-Mar-16 9:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.