Multithreading - Modify A Generic Invoke Method To A Generic BeginInvoke Method?

Oct 7, 2010

I have been using a pretty slick generic invoke method for UI updating from background threads. I forget where I copied it from (converted it to VB.NET from C#), but here it is: Public Sub InvokeControl(Of T As Control)(ByVal Control As t, ByVal Action As Action(Of t))

[Code]....

View 1 Replies


ADVERTISEMENT

Strongly-typed Generic Method Invokes Its Argument's Base Class Method Instead Of A Shadowed Method In T?

Oct 19, 2010

Consider a MyForm class that contains a shadowed implementation of Show(). It also contains a CreateForm() method, which accepts an instance of the form and calls the shadowed sub:

[Code]....

View 3 Replies

.net - Can A Generic Version Of A Derived Class Override A Base Method Using The Generic Type

Apr 13, 2012

Consider:

Public MustInherit Class Column
Public ReadOnly Property ReturnSomethingUseful() As Object
Get
'return something useful

[code]....

But this gives the following error:

Public Overrides Function ParseValue(sValue As String) As Boolean'
cannot override 'Public Overridable Function ParseValue(sValue As String) As Object'
because they differ by their return types.

I accept that you can't do this, but I'd like to be able to preserve the semantics of what I'm. trying to do, which is to have an untyped version that deals with Object, but a typed version in derived classes that knows about the specific type T.

View 2 Replies

Constrain A Generic Method / Extension Method To Numeric TYPEs Only?

Sep 16, 2010

Write an overload for every numeric type or if possible constrain a generic extension method to just numeric types.

View 2 Replies

C# - Create A Generic Method In A Class?

Apr 28, 2010

I am really trying to follow the DRY principle. I have a sub that looks like this?

Private Sub DoSupplyModel
OutputLine("ITEM SUMMARIES")
Dim ItemSumms As New SupplyModel.ItemSummaries(_currentSupplyModel, _excelRows)
ItemSumms.FillRows()

[Code]...

View 4 Replies

Using TrueForAll Method In Generic List?

Jun 7, 2009

I have a class myClass. MyClass has a property myName. I have a generic list myList(of myClass). I have to check if value of myName in all myClass objects in myList is same and is equal to a string myString. I have created a method:

Private Function IsMatching(ByVal objMyClass As MyClass, ByVal strMyString As String) As Boolean
If objMyClass.MyName = strMyString Then
Return True
Else
Return False
End If
End Function
Now I want to use is TrueForAll method of Generic list. How can I use it ?

If there was No second Parameter in IsMatching method, I could have simply used
myList.TrueForAll(AddressOf IsMatching)
But since there is a parameter strMyString, I dont understand how can I use IsTrueForAll method. How can I use IsTrueForAll method in this scenario.

View 2 Replies

.net - Use Generic Method To Replace Duplicated Properties?

Jul 29, 2011

Currently my code has the following properties:

[Code]...

View 3 Replies

C# - Generic Method Overloading Compilation Error In VB?

Aug 5, 2009

I have a problem with the VB.NET compiler failing to compile a class (in a separate C# assembly) which contains two overloads of a method with generic arguments. The equivalent code in C# compiles against the same assembly with no errors. Here are the two method signatures:

protected void SetValue<T>(T newValue, ref T oldValue)
protected void SetValue<T>(T? newValue, ref T? oldValue) where T : struct

Here is the code to three assemblies that demonstrate the problem. The first is the C# assembly with a Base class that implements the generic methods. The second is a C# class derived from Base and calls both overloads of SetValue correctly. The third is a VB class also derived from Base, but fails to compile with the following error message:

[Code]...

Am I doing something wrong in the VB code, or are C# & VB different when it comes to generic overload resolution? If I make the method arguments in Base non-generic then everything compiles correctly, but then I have to implement SetValue for every type that I wish to support.

View 2 Replies

Write A Generic Extension Method For Every Enumerable(Of T)?

May 30, 2012

After looking at this thread.>>

How to randomize the alphabet I have decided to make it into an extension method for a String and a List.

Note: Please see the following post if you are still using VB.Net 2002, 2003 or 2005

this code is for use with 2008 and later versions of VB.Net

String.Mix and also List.Mix I was trying to write a generic extension method for every Enumerable(Of T)

I settled on just doing it for a STRING

[Code]...

View 16 Replies

.net - 'ObjectDataSource1' Could Not Find A Non-generic Method 'getCOMDLs' That Has Parameters:

Sep 27, 2010

Getting this error message and I am not able to figure out why. Here is my code:

<asp:TextBox ID="searchParam" Width="250px" runat="server"></asp:TextBox><asp:button ID="btnSearch" runat="server" Text="Search" />
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="getCOMDLs" TypeName="NewEmployee">

[Code]...

View 1 Replies

.net - Creating A Generic Method For Converting String To Nullable Numbers

Jun 19, 2009

I have 3 similar functions, that only change based on numeric type:

<Extension()> _
Public Function ToNullableShort(ByVal str As String) As Short?
Dim intReturn As Short

[Code].....

I was trying to make a generic function out of this, but couldn't do it. How can I make a generic function that will take a specific T and make it a Nullable(of T)?

View 2 Replies

.net - Generic List Extension Method ForEach Stopped Working?

Dec 16, 2010

I have a custom list that inherits Generic.List and it has a method for deselecting all of the members named DeselectAll It has looked like this for a few weeks and has worked fine.

Public Sub DeselectAll()
MyBase.ForEach(Function(p As Publipostable) p.ModeEnvoiChoisi = Nothing)
End Sub

Today, it stopped working ?!? I reverted to an earlier version using delegates and that works fine...

Public Sub DeselectAll()
MyBase.ForEach(AddressOf DeselectModeEnvoi)
End Sub

[code]....

Edit: Stopped Working meaning it no longer sets the property p.ModeEnvoiChoisi to Nothing on each item in the list. The DeselectAll method gets called, but all the items retain their previous values...

View 1 Replies

Search A Generic List - Keep Getting:Delegate To An Instance Method Cannot Have Null 'this'?

Feb 16, 2009

I'm trying to search a generic list of 'User' business objects which has a property called 'Username': If (From u In colUsers Select u.Username Where Username.Equals(strUsername)).Count > 0 ThenI keep getting:Delegate to an instance method cannot have null 'this'.

View 16 Replies

Is There A Concept Of "Generic Structure" Similar To Generic Collections, Generic Classes

Dec 16, 2009

We have migrated our Vb6 application to VB.NET using a third party tool. Now we are in a process of Refactoring and introducing object oriented concepts in the application.

In VB6, we were using structures in many places. As a part of introducing object oriented programming,

1. is it a good idea of changing all Structures to Classes? or Is there a concept of "Generic Structure" similar to Generic collections, Generic classes?

2. Can some one guide me any source containing guide lines or best practices for applications that are migrated to VB.NET from VB6 and implementing object oriented programmaing.

View 3 Replies

Get Type Of Derived Generic List Class From List Item Method?

Mar 23, 2011

Public Class notifierMain
Public Class Contacts
Inherits List(Of row)
Public Sub New()

[code]....

When I debug this winforms application I get curType = "notifier.notifierMain+Contacts+row" I want to the Validate function to know it is in MyContacts. How do I do this?

View 3 Replies

Multithreading - Two Different Approaches To Generic Cross-threaded Operations; Which Is Better?

Feb 15, 2011

I recently read about using SynchronizationContext objects to control the execution thread for some code. I have been using a generic subroutine to handle (possibly) cross-thread calls for things like updating UI controls that utilize Invoke. I'm an amateur and have a hard time understanding the pros and cons of any particular approach. I am looking for some insight on which approach might be preferable and why.Update: This question is motivated, in part, by statements such as the following from the MSDN page on Control.InvokeRequired

View 1 Replies

.net - Determining A Generic Type At Runtime In Non-Generic Class

Aug 14, 2010

I have a Journal that records entries for different types: Journal(Of ParentT)

[Code]....

View 2 Replies

Construct A Generic Interface Class With Generic Functions

Nov 25, 2011

I am trying to construct a generic interface class with generic functions. My goal was to use this to implement multiple worker classes for database interaction that have the same basic functionality. Each class will deal with different object for example, category, product or supplier but unless the the functions in the interface are generic that this won't work.This is the interface code that I have but I don't know if I have done it correctly. [code]

View 2 Replies

.net - Creating A Generic List Of A Generic Type

Jun 30, 2011

I am trying to create a list of a generic type in vb.net 2.0 framework.
This is the generic type definition:

Public Class GenericParamMap(Of T)
Public Sub New(ByVal pParamName As String, ByVal pPropValue As T)
mParamName = pParamName

[Code]....

The compiler does not allow a "T" in the method's parameter because it's not defined, but I'm not sure how or where to define it. I thought it was okay to have a generic method definition.

View 2 Replies

Generic Cannot Instantiate Instance Of The Generic Type With New?

Feb 8, 2012

I am trying to write a generic method, to avoid code duplication, which will create or activate a Form as an MDI children, based on its type. But I have to lines in error (see comments).

[Code]...

View 4 Replies

VS 2008 FilesystemWatcher - Treeview.invoke - Error "invoke Or Begininvoke Cannot Be Called On A Control Until The Window Handle Has Been Created"

Aug 27, 2010

I have a filesystewatcher object. On it`s event it runs a procedure which fills a treeview with a data. I had problems with treeview methods, but when I run them using invoke method everything is ok. But I still have one problem. When I load the form for the first time, everything works fine. But, when I then close the form (me.dispose, me.close), and load it once again, when Filesystemwathcer start the procedure i have an exception "invoke or begininvoke cannot be called on a control until the window handle has been created" trying to run a treeview.invoke method?

View 9 Replies

Cant Use The Method - Invoke ?

Nov 11, 2009

Public Class StateObject
Public workSocket As Socket = Nothing
Public Const BufferSize As Integer = 1024
Public buffer(BufferSize) As Byte

[CODE]....

View 3 Replies

Invoke A Method Rather Than A Control?

Aug 20, 2009

1. On the main form a scanner class is instantiated that (in the scanner's constructor) sets the scanner settings (baud rate, parity, etc) and opens the scanner for use

2. A barcode is scanned (via a scanner connected to the device in a seral port) while on the main form

3. In the scanner class, the DataRecieved event gets the needed info from the scanned code.

4. Then that info is passed back to the main form to a method RunCommandCode (which takes the scanned info as an argument)

5. On the main form the RunCommandCode calls another method CommandCodeHandler, passing the scanned info again

6. In the CommandCodeHandler sub a method is called in a Utils class (SetSelectedTab), which interacts with the form itself (determines how many tabs exist on a tab control), which is the reason for the invoke in the first place

So, before I figured out I needed to use the Invoke method (and, more specifically, that the scanner was working in a different thread), I was getting an error in step 6 on the line that got the TabControl.TabPages.Count.

[code]...

View 2 Replies

Using The Invoke Method Of IDispatch?

Aug 31, 2010

I am implementing a custom iDispatchLLInvoke handler for VB.NET - some of this is working.So Far - I have been able to intercept and provide custom handling of simple functions and property calls - but I am stuck when I try to set a property and get an error "Invalid Pointer (Exception from HRESULT: 0x80004003 (E_Pointer))".

I am using the new .NET 4.0 ICustomQueryInterface to do this. In Summary - I intercept and provide my own implementation of iDispatch - I load the dispIDs on the first call - and return a the dispID for each call within GetIDsOfNames - this ID is than passed to Invoke where reflection is used to get the value and return the result.

When I attempt to set a property - a call is made to GetIDsofNames and I return a valid dispID - the application than crashes with the error above and no call is made to Invoke.As a result - I am assuming that the issue relates to my interface definition been wrong becase the code never get's back to .NET code - see below for this code:

<ComImport(), Guid("00020400-0000-0000-C000-000000000046"), InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IDispatch
Sub GetTypeInfoCount(ByRef pctInfo
As UInt32)

[code]....

View 3 Replies

VS 2008 Accessing Something With A Generic Generic?

Jun 19, 2012

If i have an object that implements an interface (and don't know the exact object) i can call a sub (DoSomething) by going:

vb
Dim iObj = trycast(something, iInterface)
if iObj isnot nothing then
iObj.DoSomething()
end if

How can I do this for a Generic? such as...

vb
Public Class TestClass(of T)
Public sub DoSomething()
....
end class

View 2 Replies

Invoke An Instance Function Delegate On An Instance Of A Generic Type?

Aug 4, 2010

D is a dictionary whose entry values are of Type T..What I'm attempting to do is have a delegate like "Serializer" below that I can invoke on an instance of T, such as "Entry.Value" below.Please see the "return Entry..." line below for my wishful thinking.[code]

View 2 Replies

.net :: Using Reflection To Invoke An Extension Method?

Nov 16, 2011

I've created a MyFunc extension (in Module Extensions) for all the base types as well as generic arrays, ICollection(Of T) and Dictionary(Of String,T):

Function MyFunc(Of T)(a() As T) As String
Function MyFunc(Of T)(collection As ICollection(Of T)) As String
Function MyFunc(Of T)(dict As Dictionary(Of String,T)) As String

[code].....

View 1 Replies

.NET Invoke DLL Method With ByRef Arguments?

Apr 3, 2009

Using VB.NET, is there a way to pass a reference argument when invoking a function in a dll.

Suppose I want to pass arg2 as a reference argument, how would I do that?

method.Invoke(obj, New [Object]() {arg1, arg2, arg3})

In other words I want to point arg2 to something else within the invoked function.

View 2 Replies

C# - Invoke A Method On A Class Using Attributes?

May 29, 2012

I want to invoke a method on a class that i have a reference to. The method that I want to call has a custom attributes. Currently I can find this attributes and call the property of my class Attribute.

is there a way to invoke that method ?

PS/ The project is written in vbnet, but I think the solution is the same in c#.

View 1 Replies

Invoke A Method With (of T) Parameter Using Reflection

May 5, 2011

I'm trying to make this code with reflection since I want it to manage Technician and other types too.

[Code]....

View 1 Replies







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