MultiThreading - Delegate Does Not Work

Oct 6, 2010

In my application, I have a MainWindow with a ToolStripProgressBar and a ToolStripStatusLabel.

This properties:
Property ProgressBarPercantage() As Integer Implements BCSXPSearchTool.Presenter.IMainView.ProgressPercentage
Get
Return Me._progressbarpercentage
[Code] .....

The code above is working. But if I change the sub runproc() to:
Public Sub runproc()
Dim statusToSub As delegateStatusTo = AddressOf statusTo
Dim percToSub As delegatePercTo = AddressOf percTo
' statusToSub.Invoke("Test")
percToSub.Invoke(50)
End Sub

It doesn't work. I get an exception:
InvalidOperationException

I got the text something like:
The access to the control, created by another thread from another thread is not allowed.
I'm using Visual Studio 2008 Express + VB 2.0.

View 3 Replies


ADVERTISEMENT

Multithreading - Delegate Within A Delegate?

Mar 23, 2010

I am trying to write a VB.NET alternative to a C# anonymous function.I wish to call Threading.SynchronizationContext.Current.Send which expects a delegate of type Threading.SendOrPostCallback to be passed to it. The background is here, but because I wish to both pass in a string to MessageBox.Show and also capture the DialogResult I need to define another delegate within. I am struggling with the VB.NET syntax, both from the traditional delegate style, and lambda functions.My go at the traditional syntax is below, but I have gut feeling it should be much simpler than this:

Private Sub CollectMesssageBoxResultFromUserAsDelegate(ByVal messageToShow As String, ByRef wasCanceled As Boolean)
wasCanceled = False

[code].....

View 2 Replies

Figuring Out Which Multithreading Approach To Utilize In Current Work Project?

Apr 25, 2012

figuring out which multithreading approach to utilize in my current work project. Since I've never written a multithreaded app in my life, this is all confusing and very overwhelming.I've been assigned to take over work on a control application for a piece of test equipment in my companies R&D lab. The program has to be able to send and receive serial communications with three different devices semi-concurrently. The original program was written in VB 6 (no multithreading) and I did plan on just modding it to work with the newer products that need to be tested until it posed a safety hazard when the UI locked up due to excessive serial communications during a test. This resulted in part of the tester hardware blowing up, so I decided to try rewriting the app in VB.Net as I'm more comfortable with it to begin with and because I thought multithreading might help solve this problem.

My plan was to send commands to the other pieces of equipment from the main app thread and spin the receiving ends off into their own threads so that the main thread wouldn't lock up when timing is critical. However, I've yet to come to terms with my options. To add to my problems, I need to display the received communications in separate rich text boxes as they're received while the data from one particular device needs to be parsed by the main program, but only the text that results from the most current test (I need the text box to contain all received data though).

So far, I've investigated delegates, handling the threads myself, and just began looking into BackgroundWorkers. I tried to use delegates earlier today, but couldn't figure out a way to update the text boxes. Would I need to use a call back function to do this since I can't do it in the body of the delegate function itself? The problem I see with handling threads myself is figuring out how to pass data back and forth between the thread and the rest of the program. BackgroundWorkers, as I said, I just started investigating so I'm not sure what to think about them yet.

View 1 Replies

Multicast Delegate: Represents A Multicast Delegate; That Is, A Delegate That Can Have More Than One Element In Its Invocation List?

Jan 30, 2010

from the documentation we have this: Multicast Delegate: Represents a multicast delegate; that is, a delegate that can have more than one element in its invocation list.

so am i right to say that Multicast delegate is no different from a normal delegate other than the fact that it has arguments. so System.Action is a 'normal' delegate whereas System.Action(T)(Byval obj as T) is a multicast delegate?

View 5 Replies

Delegate - BeginInvoke - EndInvoke - Clean Up Multiple Async Threat Calls To The Same Delegate?

Feb 9, 2010

I've created a Delegate that I intend to call Async.

[Code]...

View 2 Replies

Get A Error" Method 'Private Shared Sub Ping Does Not Have A Signature Compatible With Delegate 'Delegate Sub ?

Jun 1, 2010

Code:
Public Class SendPings
Shared Sub New()
AddHandler Post.Saved, AddressOf Post_Saved[code].....

I get a error" Method 'Private Shared Sub Ping(item As BlogEngine.Core.IPublishable, itemUrl As System.Uri)' does not have a signature compatible with delegate 'Delegate Sub WaitCallback(state As Object)'.

View 4 Replies

Why Use A Delegate

Apr 22, 2009

While reading this threadthe code sample there came from MSDN, which was used to demonstrate the use of a delegate. I know what Delegates are. And I know how they work when it comes to things like crossing threads and even sinks.... how ever, the sample given is a simplecontrived example, and I'm wondering why/when would I use a delegate in this situation? Or in any situation? In my head, it seems it would have been easier/cleaner to call the function pointed to directly...

View 18 Replies

LINQ Group By Multiple Values Does Not Work Well But Work Well In C#

May 29, 2012

I found that when group by multiple values does not work well with VB.NET, but it works well with C# ,here are my code, is there something wrong with my VB.NET Code? Here is my VB.NET code:

[Code]...

View 1 Replies

.net - Already Defined Delegate?

Feb 11, 2010

I heard once that .net introduced an already defined delegate with no parameter that we could use instead of creating one.

View 1 Replies

Addhandler With A Delegate?

Nov 23, 2009

I came across a snippet of C# code which is very useful. I am trying to convert it to VB.NET, but can't seem to.

timer.Tick += delegate { panel.Children.Add(source); timer.Stop(); };

Is it possible to translate this to something similar in VB?

View 7 Replies

Anonymous Delegate From C#

Jun 28, 2010

I have below code in C#:

[Code]...

View 3 Replies

Convert Delegate From C# To .net?

Aug 3, 2011

I'm having trouble converting a C# delegate to VB.NET.

How can this be done?

public MainForm()
{
InitializeComponent();
_twain = new Twain(new WinFormsWindowMessageHook(this));
_twain.TransferImage += delegate(Object sender, TransferImageEventArgs args)

[Code]...

View 2 Replies

Convert Delegate From C# To VB?

Oct 28, 2011

how can I convert the following code from C# to VB without exposing "variable" as global variable.

[Code]...

View 3 Replies

Converting Delegate From C#

Dec 31, 2009

I'm in the process of converting some existing code to VB. However, I'm running into a bit of a snag. It seems that in C#, a delegate can have a return value, but not so in VB. So my question is, how would I convert the following VB code to handle this?.[code]

View 3 Replies

Convertion From C# To .net Using Delegate?

Jun 20, 2009

im developing a way of calculationg differentil equations in VB 2008 using the 4th order ruge-kutta method. I pursched a book by Jack Xu called "Practical WPF Graphics programming".

[Code]...

View 2 Replies

ThreadPool And Delegate In C# To .NET?

Jan 1, 2010

how this is written in VB.NET? This was an example I found on [URL]

ThreadPool.QueueUserWorkItem(delegate
{
var channelFactory = new ChannelFactory<ISimpleService>("*");
var simpleService = channelFactory.CreateChannel();
var asyncResult = simpleService.BeginGetGreeting("Daniel", null, null);

[code]....

View 3 Replies

How To Do Multithreading

Jan 18, 2010

What is multithreading and how do i do it in vb.net?

View 2 Replies

PerformClick() Doesn't Work - How To Make It Work

Feb 2, 2011

I have an application that requires data be entered, and after entering, a button is clicked to process that data. Clicking the button works just as it should--the data is processed properly. In constructing a test module, I provide a set of data values, followed by:

btnWhatever.PerformClick()

Nothing happens. I have used this syntax for years, and it has always worked flawlessly. I have triple checked everything else and isolated the problem to the failure of the PerformClick(). The PerformClick() is in a test subroutine that does nothing but fill textboxes and labels with default data, then calls the PerformClick() on the button to begin processing. Again, the button works fine, the data is entered as it should be, but the PerformClick() does not fire the click event.

View 21 Replies

VS 2008 Could Not Get Form To Work On Work Computer

Aug 21, 2009

I have a form that works on my local Machine I created into. I have Office 2007 on this machine. I created the Form with the Excel 12 Reference. I move the Entire conetence of the Project folder to my work computer. Which has Office 2003. Do I need to recreate the form with the Excel 11 reference. I could not get the form to work on work computer. IT has a com error. I am acessing the EXE for the debug folder w/in the Bin Folder.

View 7 Replies

.net - Addressof Syntax Without Delegate

Jul 8, 2011

I am using this delegate to invoke my methode:

[Code]...

View 2 Replies

AddHandlers : Does Not Have The Same Signature As Delegate?

Apr 5, 2009

for few solutions it work outs well but not for the following code. I find an error when executing the following code. I find an error :

ErrorMethod 'Public Sub test()' does not have the same signature as delegate 'Delegate Sub DataRowChangeEventHandler(sender As Object, e As System.Data.DataRowChangeEventArgs)'.C:UsersKashifDocumentsVisual Studio

[code].....

View 3 Replies

Anonymous Delegate Translation From C#?

Dec 23, 2008

I have a problem in translating a piece of C# code

(
http://www.codeproject.com/KB/WPF/VMCommanding.aspx)static bool ConfigureDelayedProcessing(DependencyObject depObj, ICommandSink sink) { bool isDelayed = false;

[code]....

View 7 Replies

C# - Create A Delegate For A .NET Property?

Apr 7, 2009

I am trying to create a delegate(as a test) for: Public Overridable ReadOnly Property PropertyName()As String My intuitive attempt was declaring the delegate like this:

[code]...

So the question is, how do I make a delegate for a property?

View 6 Replies

C# - Pass A Property As A Delegate?

Jul 30, 2010

This is a theoretical question, I've already got a solution to my problem that took me down a different path, but I think the question is still potentially interesting.Can I pass object properties as delegates in the same way I can with methods? For instance:

Let's say I've got a data reader loaded up with data, and each field's value needs to be passed into properties of differing types having been checked for DBNull. If attempting to get a single field, I might write something like:

if(!rdr["field1"].Equals(DBNull.Value)) myClass.Property1 = rdr["field1"];

But if I've got say 100 fields, that becomes unwieldy very quickly. There's a couple of ways that a call to do this might look nice:

myClass.Property = GetDefaultOrValue<string>(rdr["field1"]); //Which incidentally is the route I took

Which might also look nice as an extension method:

myClass.Property = rdr["field1"].GetDefaultOrValue<string>();

Or:

SetPropertyFromDbValue<string>(myClass.Property1, rdr["field1"]); //Which is the one that I'm interested in on this theoretical level

In the second instance, the property would need to be passed as a delegate in order to set it.

View 7 Replies

Combining Delegate And Template?

Dec 22, 2009

Try5Times will try a function for 5 times.that function can have any number of argument and return a boolean.

If the function return false, try again.

If the function return true, stop.

How to make such function and delegate? Is there a general delegate?

View 3 Replies

Convert C# Delegate Function?

Oct 2, 2011

Here there's an old question about this code.

xmpp.OnLogin += delegate(object o)
{
xmpp.Send(

[code]....

View 2 Replies

Convert Code C# To Delegate

Jun 8, 2012

I'm trying to convert the c # code of a sample code to vb.net but I could with the following line of code. it is an event, delegate. but I can not build a functional structure.

[Code]....

View 1 Replies

Convert Lines Of Delegate From C#

Mar 19, 2012

I have a code from Fleck that actually works fine in the C# (no errors)and this is a line in a class library:[code]can someone tell me what is the valid vb .net code for that?

View 1 Replies

Converting Interface With Delegate From Vb To C#

Aug 26, 2011

I've got interface:

[Code]...

View 2 Replies

Delegate Params Not Being Mismatched

Apr 20, 2010

I'm having an issue with an application suite I'm developing. The bulk of the work is done in a backend dll that relies heavily on delegate subs in the different apps.

The problem I'm having is, I have a lot of these delegates typed to require a parameter. (eg, Public Delegate Sub DelTypeA(ByRef param As Object)). The individual methods will have a DelTypeA as one of their params, and I will pass it AddressOf functionA that has that signature.

This works fine for strong typing as long as the signature is something incorrect (2 params, a byval instead of a byref). But if functionA has NO params, the delegate is still created!

This works fine if I genuinely don't need to use a param, eg if the sub is simpler and I would have ignored the param anyway. But I want the strong typing to work here.

EDIT: I should add that invoking the delegate also works fine for simpler subs; the param is just not passed because it had nowhere to go. But I want to force all the subs to match the signature and do their own ignoring of the param

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved