Click here to Skip to main content
15,914,111 members
Home / Discussions / C#
   

C#

 
AnswerRe: Show panel after a job is completed Pin
BillWoodruff1-Mar-16 1:00
professionalBillWoodruff1-Mar-16 1:00 
QuestionConditional Mathematical Statements Pin
Member 1226553728-Feb-16 21:39
Member 1226553728-Feb-16 21:39 
AnswerRe: Conditional Mathematical Statements Pin
Pete O'Hanlon28-Feb-16 22:08
mvePete O'Hanlon28-Feb-16 22:08 
AnswerRe: Conditional Mathematical Statements Pin
Sascha Lefèvre28-Feb-16 22:09
professionalSascha Lefèvre28-Feb-16 22:09 
Questionicon/image in datagridview Pin
Any_name_at_all28-Feb-16 1:52
Any_name_at_all28-Feb-16 1:52 
AnswerRe: icon/image in datagridview Pin
Dave Kreskowiak28-Feb-16 4:25
mveDave Kreskowiak28-Feb-16 4:25 
GeneralRe: icon/image in datagridview Pin
Any_name_at_all28-Feb-16 5:52
Any_name_at_all28-Feb-16 5:52 
QuestionHow does Observable.Join work? Pin
Kenneth Haugland27-Feb-16 18:38
mvaKenneth Haugland27-Feb-16 18:38 
The documentation is really poor with the Rx functions:
Observable.Join(TLeft, TRight, TLeftDuration, TRightDuration, TResult) Method (System.Reactive.Linq)[^]

Got a little bit better by reading Lee's online book[^] and seeing the comments below this[^] Channel 9 video. So I finally managed to get something working (it is just a timer that tells for how long the left mouse button was pushed down):
C#
var MouseDown = Observable.FromEventPattern<MouseButtonEventArgs>(this, "MouseDown");
var MouseUp = Observable.FromEventPattern<MouseButtonEventArgs>(this, "MouseUp");

var LeftMouseButtonPressedDuration = Observable.Join(
                  MouseDown
                  .Where(evt => evt.EventArgs.ChangedButton == MouseButton.Left)
                  .Select(_ =>
                  {
                      DateTime now = DateTime.Now;
                      return now;
                  }
                  ),
                  MouseUp
                   .Where(evt => evt.EventArgs.ChangedButton == MouseButton.Left)
                   .Select(_ =>
                    {
                        DateTime now = DateTime.Now;
                        return now;
                    }
                    ),

                  MouseDownTimeStamp => MouseDown,
                  MouseUpTimeStamp => Observable.Empty<DateTime>(),

                  (TimeDown, TimeUp) =>
                  {
                      TimeSpan MousePressedDuration = TimeUp - TimeDown;
                      return " Total duartion is: " + MousePressedDuration.ToString(@"ss\:fff");
                  }
                );

LeftMouseButtonPressedDuration.Subscribe(evt =>
{
    txtMainWindow.Text += Environment.NewLine + evt.ToString();
});

The two first sections are really easy to grasp, as well as the last function. But it is the third and fourth function inside Join that I really don't understand or even fully comprehend how to use. I assumed that it had something to do with how the events were interpreted. I assume that the 4th section,
C#
MouseUpTimeStamp => Observable.Empty<DateTime>()

, is telling the compiler that when a new mouse down event happens, the mouse up will be cleared. If I changed the code slightly and put Publish() behind it:
C#
MouseDownTimeStamp => MouseDown.Publish(),
 MouseUpTimeStamp => Observable.Empty<DateTime>(),

It stored all the times since the first mouse down was pressed. Like a cross contry ski race where everyone starts at the same time, but arrive at the goal at different times.

So I tried to re-create the code that Lee had in his online book:
C#
var Interval_50ms = Observable.Interval(TimeSpan.FromMilliseconds(50))
    .Take(10);

var Interval_100ms = Observable.Interval(TimeSpan.FromMilliseconds(100))
    .Take(5)
    .Select(i => Convert.ToChar(i + 65).ToString().ToUpper());

var tt = Observable.Join(
    Interval_50ms,
    Interval_100ms,
    s => Interval_50ms,
    c => Observable.Empty<char>(),
    (s, c) => { return s.ToString() + ", " + c.ToString(); })
    .Subscribe(Console.WriteLine);

The output was just plain bizzare, at least to me:
3, A
3, A
3, B
6, D
8, E

I expected something like:
0, A
2, B
4, D
6, E

or at least an interval 2 between each char. What Am I doing wrong and/or what have I not understood here?
AnswerRe: How does Observable.Join work? Pin
Kenneth Haugland28-Feb-16 12:15
mvaKenneth Haugland28-Feb-16 12:15 
SuggestionRe: How does Observable.Join work? Pin
John Torjo28-Feb-16 18:44
professionalJohn Torjo28-Feb-16 18:44 
GeneralRe: How does Observable.Join work? Pin
Kenneth Haugland28-Feb-16 19:13
mvaKenneth Haugland28-Feb-16 19:13 
GeneralRe: How does Observable.Join work? Pin
John Torjo28-Feb-16 19:17
professionalJohn Torjo28-Feb-16 19:17 
GeneralRe: How does Observable.Join work? Pin
Kenneth Haugland29-Feb-16 18:40
mvaKenneth Haugland29-Feb-16 18:40 
GeneralRe: How does Observable.Join work? Pin
John Torjo29-Feb-16 19:40
professionalJohn Torjo29-Feb-16 19:40 
QuestionGrid View Filtering Pin
Member 1235559027-Feb-16 3:07
Member 1235559027-Feb-16 3:07 
AnswerRe: Grid View Filtering Pin
Afzaal Ahmad Zeeshan27-Feb-16 4:09
professionalAfzaal Ahmad Zeeshan27-Feb-16 4:09 
Questionwhy password is not decrypting Pin
Veena Hosur25-Feb-16 23:13
Veena Hosur25-Feb-16 23:13 
AnswerRe: why password is not decrypting Pin
Richard MacCutchan26-Feb-16 0:20
mveRichard MacCutchan26-Feb-16 0:20 
GeneralRe: why password is not decrypting Pin
Veena Hosur26-Feb-16 0:52
Veena Hosur26-Feb-16 0:52 
GeneralRe: why password is not decrypting Pin
Richard MacCutchan26-Feb-16 0:55
mveRichard MacCutchan26-Feb-16 0:55 
GeneralRe: why password is not decrypting Pin
Nathan Minier26-Feb-16 1:25
professionalNathan Minier26-Feb-16 1:25 
GeneralRe: why password is not decrypting Pin
Sascha Lefèvre26-Feb-16 1:44
professionalSascha Lefèvre26-Feb-16 1:44 
AnswerRe: why password is not decrypting Pin
ZurdoDev26-Feb-16 4:01
professionalZurdoDev26-Feb-16 4:01 
GeneralRe: why password is not decrypting Pin
Richard MacCutchan26-Feb-16 6:18
mveRichard MacCutchan26-Feb-16 6:18 
GeneralRe: why password is not decrypting Pin
ZurdoDev26-Feb-16 6:23
professionalZurdoDev26-Feb-16 6:23 

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.