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 6176283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:04:23+00:00 2026-05-24T00:04:23+00:00

I imagined that WndProc is called on another thread rather than main UI thread.

  • 0

I imagined that WndProc is called on another thread rather than main UI thread.

I was right, so I thought that simply using InvokeRequired and Invoke on the form was enough to show a messagebox on the UI thread.

I was wrong. And I don’t understand why.

How can I go around this problem?I’m looked around google but didn’t find a solution.

What I’m trying to do is simply raising a custom event (ClipboardUpdate) when clipboard changes

the messagebox was just a test but didn’t work, while just changing something like a string (a private field of the form) works, but it’s not a good thing this behaviour because is a cross-thread operation in an unsafe way.

Update 1:

I don’t have the code here because I created it on a friend’s computer, however I can explain exactly what I wrote Because is short.
I created a basic winform with visual studio, without anything.
I used AddClipboardFormatListener (interop, but it’s quite easy as a function, return int and accept IntPtr) function (on a windows 7 OS) to just detect WM_CLIPBOARDUPDATE message, inside winproc (a simple if, *if (e.Msg == ClipboardExtension.WM_CLIPBOARDUPDATE) DoClipboardUpdate();*).

Now the DoClipboardUpdate do this:

if (InvokeRequired)
    Invoke(new VoidDelegate(OnClipboardUpdate));//Void delegate it's a delegate that doesn't take
    // Params and returns void
else
    OnClipboardUpdate();

Quite easy right? OnClipboardUpdate just do this:

if (ClipboardUpdate != null) ClipboardUpdate(null,EventArgs.Empty);

ClipboardUpdate is an event declared in this way:

public event EventHandler<EventArgs> ClipboardUpdate;

In the end, the only method subscrived to ClipboardUpdate event has this inside:

MessageBox.Show("test");

What happens when I run the code? The event is triggered (I tried with an exception and it works) and the messagebox doesn’t popup, however I can’t interact anymore with my form because it behaves as if a popup was opened (this is the “normal” behaviour when you open a popup on a different thread, that’s why I said that).

Any suggestion on how to solve this?

  • 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-05-24T00:04:24+00:00Added an answer on May 24, 2026 at 12:04 am

    I didn’t understand why it happens but I created a new project and opening a messagebox from WndProc works fine, maybe some thread corrupted main thread memory, I don’t know this but as others stated wndproc is the ui thread and should work

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine that I want to create an array from another array like this: $array
I imagined that publishing a game to xbox live would make it available all
I'm trying to impose a @Oneto7 association. I'd have imagined an attribute that specifies
I naively imagined that I could build a suffix trie where I keep a
I have two classes. One is called Employee and the other EmployeeDetails that has
Recently I had to deal with a problem that I imagined would be pretty
In my main activity, I would like to have it set up, so that
I've been trying to create what I would have imagined would be a rather
Imagine that you have a simple site with only 2 pages: login.aspx and secret.aspx.
Imagine that you want to develop a non-trivial end-user desktop (not web) application in

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.