Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9061467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:29:31+00:00 2026-06-16T15:29:31+00:00

I have simple WPF application where I using threads. E.g. In new thread I

  • 0

I have simple WPF application where I using threads. E.g. In new thread I get DateTime and I want return it to the TextBox in main thread. I read to do this I must use ControlDispatcher.Invoke method. But something is wrong..

namespace Bizantyjskie
{
    public static class ControlExtensions
    {

        public static void InvokeIfRequired(this Control control, Action action)
        {
            if (System.Threading.Thread.CurrentThread != control.Dispatcher.Thread)
                control.Dispatcher.Invoke(action);
            else
                action();
        }
        public static void InvokeIfRequired<T>(this Control control, Action<T> action, T parameter)
        {
            if (System.Threading.Thread.CurrentThread != control.Dispatcher.Thread)
                control.Dispatcher.Invoke(action, parameter);
            else
                action(parameter);
        }
    }

    class watki
    {
        public watki(MainWindow mw)
        {
            _mw = mw;
        }
        public MainWindow _mw;

        public void dzialaj()
        {
            Thread watek1 = new Thread(new ThreadStart(w1));
            watek1.Start();
        }

        private void w1()
        {

            string godz = DateTime.Now.TimeOfDay.ToString();
            ControlExtensions.InvokeIfRequired((value) => _mw.tb_w1.Text = value, godz);
        }
      }
     }

Problem is with

ControlExtensions.InvokeIfRequired((value) => _mw.tb_w1.Text = value,
godz);

I got an error.

Cannot convert lambda expression to type
‘System.Windows.Controls.Control’ because it is not a delegate type

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:29:32+00:00Added an answer on June 16, 2026 at 3:29 pm

    You’re calling an extension method as a static one and forgetting to pass a parameter. Change it to this:

    _mw.InvokeIfRequired(value => _mw.tb_w1.Text = value, godz);
    

    Alternatively, if you still want to call it as a static method:

    ControlExtensions.InvokeIfRequired(_mw, 
        value => _mw.tb_w1.Text = value, godz);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am pretty new to WPF. I have developed a simple application using WPF.
I have a very simple WPF application in which I am using data binding
I have a WPF database viewer application: It's a simple main window containing a
I have a simple WPF application I'm using for experimenting. I have two themes
I have created a simple (commercial) WPF application and want to distribute it with
I have a simple WPF application that uses ClickOnce to handle installing. Within this
I have a simple WPF application where I don't have any mvvm framework like
I have this simple code in a WPF application: ThreadStart start = delegate() {
I have a simple text box in a WPF application. I need to know
I'm using WPF with .NET 3.0. I have a relatively simple DataTemplate defined as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.