Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C# Windows WPF DateTime , +
Hello, have some problem with DateTime in Backgroundworker.
Any solution for this one?
I really need DateTime.
This code don't work:
        private void bw_DoWork(object sender, DoWorkEventArgs e)
            BackgroundWorker worker = sender as BackgroundWorker;
                DateTime? start = DateTimePicker1.Value;
                DateTime? end = DateTimePicker2.Value;
                DateTime now = DateTime.Now;
                if (now >= end)
This simple code works:
        private void bw_DoWork(object sender, DoWorkEventArgs e)
Posted 17-Apr-13 6:34am
Edited 17-Apr-13 6:35am
Irina Pykhova at 17-Apr-13 11:52am
look at answer about cross-threading, you should correct your code. And perhaps you should check whether end.HasValue is true and then compare with end.Value, not with end

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

It would appear you are cross threading the application. You need to use delegates if you want other threads to be able to interact with user controls (even just reading them).
You could take advantage of this code snippet
Code Snippet
private void button1_Click(object sender, EventArgs e)
      string[] A = {textBox1.Text,textBox2.Text};
    private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
      string[] S = (string[]) e.Argument;


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Peter Leow 255
1 Mika Wendelius 240
2 Zoltán Zörgő 198
3 CHill60 195
4 TheRealSteveJudge 180
0 Sergey Alexandrovich Kryukov 8,698
1 OriginalGriff 6,591
2 Peter Leow 3,982
3 Zoltán Zörgő 3,634
4 Richard MacCutchan 2,535

Advertise | Privacy | Mobile
Web04 | 2.8.150123.1 | Last Updated 17 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100