|
This might also be a direction you may want to investigate:
http://www.postsharp.org/[^]
[EDIT- Ha! Martin must have been posting just as I was! He wins ]
|
|
|
|
|
I wonder if anyone can help.
I am upgrading a Windows Application from Visual Studio 2003 to 2005. After running the conversion wizard and changing/rewriting several methods I got the app to compile (already works perfectly in VS 2003)
However when running the project with a Debugger attached in 2005 and I select the open file dialog box which executes the below code I get the error "Current Thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main Function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process.".
The stack trace is shown as
at System.Windows.Forms.FileDialog.RunDialog(IntPtr hWndOwner)
at System.Windows.Forms.CommonDialog.ShowDialog(IWin32Window owner)
at System.Windows.Forms.CommonDialog.ShowDialog()
at Pupil_Accounts_Final_App.frmmain.importbob() in C:\Documents and Settings\*****\My Documents\Visual Studio 2005\*****Accounts App V2 database upgrade\frmmain.vb:line 379
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
So I then went into my puplicMain class which invokes the form (frmmain) where the button is located for calling the code to start the threaded process to call the method to open the dialog and added the SingleThreadAttribute as shown in the main code below, however the same error is still thrown. I then added this attribute to the button click event and the method (again shown below) but again same problem again.
I have been searching about the Web for several hours trying to find a solution however found one similar article which suggested removing all old DLL files in the BIN directory, I tried this still no luck. Does anyone have any idea what my problem could be? MSDN and all my other usual methods of debugging are just not working with this...
Method for open dialog:
STAThreadAttribute() _
Private Sub importpupils_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnimportbob.Click
'starts threading to make program appear faster and optomise performance
Dim t As New Thread(AddressOf importbob)
t.Name = "Import Bob"
importPupilsThread = True
t.Start()
End Sub
<STAThreadAttribute()> _
Public Sub importbob()
'this sub open's a stream reader so bob's master file can be taken into the program
Dim file As FileStream
Dim inputstream As StreamReader
Dim temp As String
Dim item As ListViewItem
Dim i As Integer
open.Filter = "CSV File (*.csv)|*.csv"
If open.ShowDialog = DialogResult.OK Then
Try
file = New FileStream(open.FileName, FileMode.Open)
inputstream = New StreamReader(file)
Catch ex As Exception
MsgBox("A Exception has occured." + vbCrLf + ex.Message)
Exit Sub
End Try
btnimportbob.Enabled = False
Try
Do While inputstream.Peek > -1
temp = inputstream.ReadLine
item = bobslist.Items.Add(temp.Split(",", 11, StringSplitOptions.None)(0))
For i = 1 To 10
item.SubItems.Add(temp.Split(",", 11, StringSplitOptions.None)(i).Trim)
Next
Loop
Catch ex As Exception
MsgBox("A exception has occured. You may have imported the wrong file or the file is corupt" + vbCrLf + ex.Message)
inputstream.Close()
importPupilsThread = False
Exit Sub
End Try
inputstream.Close()
End If
importPupilsThread = False
btnimportseemis.Enabled = True
End Sub
Main entry point to the program publicMain
Module publicmain
Public Const appversion As String = "2.0.0"
Public Const appauthor As String = "*****"
Public Const apptitle As String = "*******"
Public MainForm As frmmain
Public importPupilsThread As Boolean = False
Public importSeemisThread As Boolean = False
Public nextThread As Boolean = False
' Main entry point in to application
' Creates new instance of the main form then shows the dialog
<STAThreadAttribute()> _
Sub Main()
MainForm = New frmmain()
MainForm.ShowDialog()
End Sub
|
|
|
|
|
Hi,
I don't think you can use STAThreadAttributes for that purpose. Here are two possible solutions:
1. do you user interaction before you start the thread;
2. or set Thread.ApartmentState before calling Thread.Start
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Luc,
Great thanks for your help on this, problem resolved. It would appear that the Thread.ApartmentState method has been depricated by Microsoft however i replaced this by the below before starting the thread and all works great thanks for your help. If this is anyhelp to anyone I have posted the code below.
Private Sub importpupils_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnimportbob.Click
Dim t As New Thread(AddressOf importbob)
t.Name = "Import Bob"
importPupilsThread = True
t.SetApartmentState(ApartmentState.STA)
t.Start()
End Sub
|
|
|
|
|
am study from book MCTS 70-536 the book that by microsoft with orange cover not the black one okay
my problem is ,,, i dont have the SourceCode CD and am at lesson
Serializtion
i have this lab that want me to serialize class called person and i must copy it from the cd and i dont know but really i need somebody to help me to can understand this lab
please someone tell me what i have to do and am just beginner and dont know how to write a class can become same like person
|
|
|
|
|
H.Hemdan wrote: am just beginner and dont know how to write a class
I am quite surpise that you are saying the you are just a beginner and don't know how to write class And you started reading MCTS- 70-536, Which is Microsoft .NET Framework Certificationm Training Kit.
I will suggest you to please buy some beginners books. Go through the Books, done some hands on, then only go for 70-536 Book.
|
|
|
|
|
Hi,
I've got a dll that is registered on a machine using
<br />
regasm /codebase blah.dll
this dll works fine
During an upgrade I copy a new version of the dll over the top (on reboot if locked)
A VB6 App (yes you red that right) then tries to run the dll and on some machines I get an automation error, this doesn't seem to be OS related and I can't find any other common factor between the machines
rerunning
<br />
regasm /codebase blah.dll
fixes the problem
Does anyone know why this might happen, is there some kind of REGASM clean up process that might notice that I deleted the old dll before the new one gets written and unregisters it?
Cheers
Russell
|
|
|
|
|
It may be because you registered the 1st copy of the .DLL with a set of GUIDs that are no longer valid in the second copy of the .DLL. If you are letting Visual Studio generate the GUIDs or are otherwise not specifically generating and assigning them manually, yourself, you can have this kind of problem. All classes and interfaces exposed through COM are done using GUIDs. If these GUIDs changes between revesions of the .DLL, just copying the new .DLL over the top of the old one will break these GUID/class/interface associations.
|
|
|
|
|
Thanks for the reply.
It seems that it's a version numbering issue, the guids are hard coded in the project at the moment, the interfaces are fine. The problems also appear to have happened since we fixed a build script issue that was failing to change the version numbers on build.
So, now i understand why the thing is breaking but now fail to see why it ever works
This should at least be a bit easier to diagnose.
I think I might sleep on it and see what the problem is.
Russell
|
|
|
|
|
I have a split container on the form. On the left panel and right panel I have tree views. I have set the tree view scroll bars to false. When the treeviews increase in size, tthe panels doesn't show any scroll bar even though autoscroll property of the panels are set to true. How can I show the scroll bars of the panel? I need to synchronise both the scroll bars later.
Regards
Surya
|
|
|
|
|
If the Dock property of your TreeView s is set to anything other than DockStyle.None the scrollbars won't show. The TreeViews must extend beyond the bounds of the panels for this to happen.
If this is not the case, then please ignore this post.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanks Henry for the reply. But I have set DockStyle.Fill for the treeviews. I want to show the scroll bars of the panels. I mean how to extend treeview beyond the bounds of the panel?
Regards
Surya
|
|
|
|
|
Surya Ayyagari wrote: But I have set DockStyle.Fill for the treeviews
That is the problem. DockStyle.Fill 'does exactly what it says on the tin' it will only ever allow the TreeView to exactly fill its containing control. It cannot grow to be larger and therefore the scrollbars are not needed.
As I said in my previous post, the TreeView must be able to extend beyond the bounds of the panel for the ScrollBar s to show up.
You might try setting Dockstyle.Top which, on reflection, should allow them to grow vertically and thence trigger the ScrollBar
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I want to control my window media with Remote control. Now i am using windows Vista. I don't how to write code and which library shall i use ple
|
|
|
|
|
Hi Guys,
I've got a WebBrowser control embedded in my desktop application. This browser loads an HTML registration form from the local host that i manipulate and query with javascript.
I need a way to test whether javascript is enabled from the client side, so that i can prompt the user to enable it. Is there any way to do this?
Regards
Tris
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
I went to the msdn website:http://msdn.microsoft.com/en-us/library/system.net.networkinformation.aspx
but looking for help writing the code in VB.
|
|
|
|
|
Do NOT post your questions in multiple forums. Pick the one forum that is the most appropriate to the subject and stick with it.
|
|
|
|
|
I have a Class named "A"
this class inherits from Windows.Forms.PictureBox
"A" has public properties
if we name properites of A as below:
A1
A2
A3
we can set values of A1, A2, A3 and All inherited properties from pictureBox
I create an instance of A in runtime and name it MyA
and then I have a PropertyGrid name Pr1
Pr1.selectedObject = MyA
Pr1 is showing all properties of MyA including all inheritec from PictureBox
I want Pr1 to show only A1,A2 and A3 and hide the rest. how can I do that????
|
|
|
|
|
This is against OOP principals. All properties etc of the base object shold be present in the deriving object.
However, Microsoft do this themselves all the time! The PictureBox is a good example. It has no browsable Text property in the property grid or in the code editor via intellisense, but it's still there as it derives from System.Windows.Forms.Control which has the Text property.
The way to achieve this is to do something like this with properties, events and methods that you don't want to be visible.
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
public class MyPictureBox : PictureBox
{
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This property is obselete", true)]
public new Color BackColor
{
get { return base.BackColor; }
set { base.BackColor = value; }
}
} This will make the BackColor property 'disappear' IF MyPictureBox is in a seperate assembly. It will not work if in the same assembly, or added as a project reference to another project - it must be a reference to a seperate dll.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Thanks for your great help.
I just wanna ask if you could help me with this in VB.NET !
it is a long time I am not working in C and I could not match your example to a VB code.
Cheers,
|
|
|
|
|
I don't really do VB - I think this is correct. I don't have VB installed on this machine so it's from memory only and untested!
Imports System
Imports System.ComponentModel
Imports System.Drawing
Imports System.System.Windows.Forms
Public Class MyPictureBox
Inherits PictureBox
<Browsable(False)> _
<EditorBrowsable(EditorBrowsableState.Never)> _
<Obsolete("This property is obselete", true)> _
Public Property BackColor() As Color
Get
Return MyBase.BackColor
End Get
Set(ByVal value As Color)
MyBase.BackColor = value
End Set
End Property
End Class
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
This is the VB code I have here, there are many properties inherited from Picturebox to this class. how can i make all of inherited properties nob-browsable!? in my test app I have an instance of this class assigned to a PropertyGrid (as selectedobject) and it is showing all of them!?!?!?
Imports System.Windows.Forms
Imports System.ComponentModel
Public Class A
Inherits Windows.Forms.PictureBox
Private _A1 As Integer
Private _A2 As Integer
Private _A3 As Integer
<CategoryAttribute("Test"), Browsable(True)> Public Property A1() As Integer
Get
Return _A1
End Get
Set(ByVal value As Integer)
_A1 = value
End Set
End Property
<CategoryAttribute("Sample"), Browsable(True)> Public Property A2() As Integer
Get
Return _A2
End Get
Set(ByVal value As Integer)
_A2 = value
End Set
End Property
<CategoryAttribute("Sample"), Browsable(True)> Public Property A3() As Integer
Get
Return _A3
End Get
Set(ByVal value As Integer)
_A3 = value
End Set
End Property
End Class
|
|
|
|
|
You will need to apply the same attributes that I posted above to EVERY property etc that you want to hide. There is no shortcut I'm afraid. The System.Windows.Forms.Control class is where most of the stuff you're seeing that you don't want comes from. That in turn derives from all of these:
Component, IDropTarget, ISynchronizeInvoke, IWin32Window, IBindableComponent, IComponent, IDisposable
If you derive from Component instead, you don't get any of the other stuff, but you then don't have a visible control. To make it visible as a control you'd need to implement IWin32Window [Edit] I think [/Edit]. I've no idea how to do that - I'm sure it is not trivial. If you decide to try, and figure it out, please write an article about it because I'd love to learn!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
modified on Monday, July 27, 2009 10:38 AM
|
|
|
|
|
Dave, your answer to this question was great...
I was just thinking about something to make this more useful..
if Class A inherits from Windows.Forms.PictureBox or whatever component and I need the Picturebox width and image to be used in my instances of A (MyA Object) how can i hide it?! I don't want to overload the inherited property. Also I couldn't use Shadowing!!!
how can i use some of inherited properties but hide them in propertyGrid...!?
Cheers,
|
|
|
|
|
If you remove the Obselete attribute, and in the getter/setter use the base values like I did, then you can continue to use the properties - they will just not be visible to the property grid or intellisense.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|