473,322 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Cannot set AllowDrop from a callback

Hello,

I am having a problem with set AllowDrop from a callback function for
any types of control boxes, ie. ListView. The following is the example
code that creates the problem. The listView1.AllowDrop never get set
and there is no error or warning as well. Also, if there is any code
after the line "listView1.AllowDrop = false;" will never get excuted.
It seems only happen to the AllowDrop property, others, such as color,
Enabled, are fine.

I appreciate if anybody can help me out here.

Thanks.
John
-------------------------------------------------------------------------------------------
public delegate void ipcEventCallback();
public static ipcEventCallback ipcEventHandler;

private void Form1_Load(object sender, System.EventArgs e)
{
// Init ipcEventCallback interface
ipcEventHandler = new ipcEventCallback(IpcEventHandler);
}

void IpcEventHandler()
{
listView1.AllowDrop = false;
}

private void button1_Click(object sender, System.EventArgs e)
{
ipcEventHandler.BeginInvoke(null, null);
}
-------------------------------------------------------------------------------------------

Nov 22 '05 #1
6 1321
Setting the AllowDrop requires that the thread enters a single-threaded
apartment when you call BeginInvoke your thread will enter a multi-threaded
apartment. Anyways I find it strange that you don't get an exception...

Gabriel Lozano-Morán
Real Software
Nov 22 '05 #2
Forgot to mention that you need to call the IpcEventHandler() synchronously
with Invoke() instead of asynchronously with BeginInvoke().

Gabriel Lozano-Morán
Real Software
Nov 22 '05 #3
Thanks for the help!

So, For this example, I should do something like
"this.Invoke(ipcEventHandler, null);" right?
And this will block the GUI thread until it's finished, right?

But why is this? Why only AllowDrop but not others (I can set any other
properties from the BeginInvoke())? Would you please point me to some
document that explains this?

Thanks again.
John
Gabriel Lozano-Morán wrote:
Forgot to mention that you need to call the IpcEventHandler() synchronously
with Invoke() instead of asynchronously with BeginInvoke().

Gabriel Lozano-Morán
Real Software


Nov 22 '05 #4
The AllowDrop property is a special case because it will register the window
as a client for drag-and-drop operations. OLE needs to be enabled on the
thread and is therefore initialized and to make sure that the operation is
thread-safe Microsoft has added a check to verify that the current thread is
running in a single-threaded apartment.

I have looked on the MDSN trying to find an article for you that somehow
explains it:
http://msdn.microsoft.com/library/de...d5972fa391.asp

Gabriel Lozano-Morán
Real Software

<jo******@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Thanks for the help!

So, For this example, I should do something like
"this.Invoke(ipcEventHandler, null);" right?
And this will block the GUI thread until it's finished, right?

But why is this? Why only AllowDrop but not others (I can set any other
properties from the BeginInvoke())? Would you please point me to some
document that explains this?

Thanks again.
John
Gabriel Lozano-Morán wrote:
Forgot to mention that you need to call the IpcEventHandler()
synchronously
with Invoke() instead of asynchronously with BeginInvoke().

Gabriel Lozano-Morán
Real Software

Nov 22 '05 #5
Hi Gabriel,

Thanks for the info. Please allow me to ask you one more question.

So, what is the right way to modify the AllowDrop field from another
thread?
I just find out that the invoke cannot be called from another thread as
well.

The code I initially posted is not the one I am using actually but it
generates the same problem. I have a GUI and a background running
thread that needs to change certain GUI things. I let the GUI provide
some delegates so the background thread can use them to operate on the
GUI when it's needed but not block the GUI. Do you think it's correct
way of doing this?

Thanks,
John

Nov 22 '05 #6
For example:

private delegate void SetAllowDropHandler(Control control, bool value);

private void SetAllowDrop(Control control, bool value)
{
if (control.InvokeRequired)
{
control.Invoke(new SetAllowDropHandler(SetAllowDrop), new object[]
{ control, value} );
}
else
{
control.AllowDrop = value;
}
}
Gabriel Lozano-Morán
MCSD .NET
Real Software
http://www.realsoftware.be
Nov 22 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
12
by: glutz7878 | last post by:
I have no trouble passing __delegate ptrs to native C functions in DLLs, however when attempting to pass the __delegate ptr to a native C++ function in a DLL I get the following runtime exception:...
1
by: chsakda | last post by:
In my Page_Load Method, I call a method by asynchronous callback to do some work. It's working fine until it calls back. Here is the problem in my callback method. Basically, I cannot redirect...
0
by: Marty Cruise | last post by:
I have a listview and its AllowDrop property is set to True. I need to detect a doubleclick, but the AllowDrop seems to always eat the first click, so the event never fires. Is there a way around...
0
by: Pawan Narula via DotNetMonster.com | last post by:
hi all, i'm using VB.NET and trying to code for contact management in a tree. all my contacts r saved in a text file and my C dll reads them one by one and sends to VB callback in a sync mode...
1
by: stillh2os | last post by:
Hello. I'm new to .NET, and I'm trying to implement a callback function. I want my managed C++ code to call an unmanaged function, passing in a callback function that the unmanaged C/C++ code...
0
by: Cylix | last post by:
I am trying to do the drag and drop effect in my simple form, I can drag a button and copy a text to outlook email, but I cannot drag it and drop to a textbox in the same application. I swear that...
1
by: Bart Steur | last post by:
Hello, I'm using VB 2005 Express. I want to implement a functionality into my app that allows users to drag an image file from explorer onto a picture box control in my app. I can't get it to...
2
by: Water Cooler v2 | last post by:
May be I've just been awake a bit too long but I can't seem to find the AllowDrop property on a System.Windows.Forms.GroupBox object in the design mode. I've set it in the code window but I am...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shćllîpôpď 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.