Dispose method: Converting from C# to VB .NET

H

Howard Kaikow

I've been trying to convert the following C# Dispose to VB .NET:


protected override void Dispose(bool disposing)

{

if (excelThread != null)

{

excelThread.Join();

}

if (disposing)

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose(disposing);

}


Using the code below following, I get the error:

Method 'Dispose' has multiple definitions with identical signatures

What am I doing wrong?


Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If Not (excelThread Is Nothing) Then

excelThread.Join()

End If

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub
 
H

Herfried K. Wagner [MVP]

Howard,

Howard Kaikow said:
I've been trying to convert the following C# Dispose to VB .NET:


protected override void Dispose(bool disposing)

{

if (excelThread != null)

{

excelThread.Join();

}

if (disposing)

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose(disposing);

}


Using the code below following, I get the error:

Method 'Dispose' has multiple definitions with identical signatures

What am I doing wrong?


Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

Where did you add the 'Dispose' method? Typically, forms, usercontrols,
etc. have an automatically generated 'Dispose' method which is part of the
"designer generated code" region. You may want to add the code to the
'Dispose' method of the designer generated code instead of adding your own
'Dispose' method.
 
H

Howard Kaikow

I thought about doing that, but the C## code did not do that, so I didn't
try.

I guess VB .NET could be doing things differently, I'll take a look.
 
H

Howard Kaikow

Ayup, that was the problem.

I guess the original C# may also have had a Dispose in the Designer, but the
author may have removed the critter.

In any case anyone's interested, I took an extra dose of my masochist
medication, I am working thru Andrew Whitechapel's book MSFT .NET
Development for MSFT Office and converting the code to VB .NET. Al the
book's code is C#, other than, as I recall, 2 examples/

A very painful exercise.
But I'm learning a lot.
 
H

Howard Kaikow

It appears that C# does not hide the Dispose in the Designer, instead the
dispose is generated outside the Designer.

VB .NET just does this the other way.

Seems like quite a needless difference between the two languages for code
generation.
 
H

Herfried K. Wagner [MVP]

Howard,

Howard Kaikow said:
It appears that C# does not hide the Dispose in the Designer, instead the
dispose is generated outside the Designer.

VB .NET just does this the other way.

Seems like quite a needless difference between the two languages for code
generation.

ACK. I would prefer the way C# handles it in VB.NET too :).
 
H

Howard Kaikow

Clear evidence of a lack of proper design/review/control processes within
MSFT.
 
C

Cor Ligthert

Howard,

Bellow are the standard conponent disposes methods from VBNet and C#. I do
not see any difference. With the exception that it is in VBNet hidden in the
windows for designer code and in C# outside that.

I hope this helps?

Cor

\\\
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub _
Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
///
\\\
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
///
 
H

Howard Kaikow

Thanx.

The problem was that the author of the C# code had removed the Dispose in
the DEsigner, so when I was converting the code to VB .NET, I missed that
there might be a Dispose in the Designer.

Oh well, we have Disposed this topic.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top