Quick Clarification About When Have To Remove Handlers In .Net
Aug 6, 2010
If I have a class with a couple of event handlers inside of it which are attached to an object that is defined within the class, am I right in thinking that I don't need to implement IDisposable to remove said handlers, even if I explicitly added the handlers myself? Also, can anyone point me in the direction of an article that explains the scope of when it is needed to remove handlers to avoid memory leaks. (I've tried searching many times but I must be screwing up my search terms.)I have a collection; every time an object is added to that collection, I add a handler to a change event of the object.When I'm done with the collection, do I need to go through each item and remove the handler before setting the reference to null?
View 3 Replies
ADVERTISEMENT
Feb 11, 2010
When you declare an object 'WithEvents' and then utilize the "Handles" clause at the end of your event methods, how does Visual Basic manage a reference change for the object? In other words, if the withevents var is set to ObjectA, then later I switch it to ObjectB (or nothing), does Visual Basic automatically both remove those handler methods from ObjectA, and attach them to ObjectB? Or do I still have a ObjectA's events being handled behind the scenes?
I ask this because if instead you use AddHandler for an object, and then switch your reference, unless you removed the handler before switching, your original object is still handled (at least I'm pretty sure that's how it works).
View 13 Replies
Jul 19, 2009
Problem: I have a document class which contains a list of objects. These objects raise events such as SolutionExpired, DisplayExpired etc. The document needs to respond to this.
Documents can sometimes exchange objects, but a single object should never be 'part' of more than one document.
My document class contains a bunch of methods which serve as event handlers. Whenever an object enters the document, I use AddHandler to set up the events, and whenever an object is removed from the document I use RemoveHandler to undo the damage. However, there are cases where it's difficult to make sure all the steps are properly taken and I might thus end up with rogue event handlers.
View 3 Replies
Jun 16, 2009
to know if a control have any handler. I have a dgv and in the editing control Showing event i add an event handler like this: VB AddHandler e.Control.KeyPress, AddressOf Grid_KeyPress_NumbersOnly This event it's added in some of the columns and for the other ones i remove it... The problem it's when the user, for example selects 3 columns where the event it's added, then if the user selects one where the event it's removed, it doesn't remove all handlers... So i have 2 solutions, when removing i put multiple removes or the other check if the event handler it's added doesn't add again. I prefer this second option, but i don't know how to check if the event it's added?
View 3 Replies
Dec 7, 2010
I am developing a VB application using the Visual Studio 2008 IDE. I was making changes to my code using the Quick Replace function when the dialog window stopped displaying. Selection of Quick Find or Quick Replace from the Edit menu, as well as use of shortcut keys (CTL+F and CTL+H) all have the same affect: the IDE loses focus but no dialog windows display. Is this a known issue with an available fix?
View 1 Replies
Feb 2, 2011
I'm using SQL Server 2008 and Visual Studio 2008 with .NET Framework 3.5. I'm teaching myself and this my first time posting a question here. And I was wondering if someone could clarify something for me.I've created a table called Classes. One of the columns is called Enrolled and is of data type tinyint (0 to 255) since the class will never have more than 50 students enrolled.In my application I created an object called ClassInfo and declared a private variable ..private _classAmt as byteMy question is this..What if someone wants a total of students enrolled for that year? Do I need to convert to a larger data type such as int32 or would it be better to set the data type as Integer in t
View 1 Replies
Mar 16, 2012
When this grabs the current process, the "current" process is the one that called this function, right? I.E., the process that is requesting this information is the current process, correct? For example, if the process that is running this piece of code right now has a pid of 1, the Process object returned by this function will tell me it has a pid of 1, correct? I cannot possibly get any other process, correct?
View 1 Replies
Jan 21, 2009
I am inclined to delve into it in the near future just to get a taste of it. I am looking into converting my single form Chat program to its WPF equivalent. The form that I am currently using have a RichTextbox control in it, I am not sure how WPF works but do I need to design a Richtextbox control using XAML/XML or just the specification on where it should be located?
View 2 Replies
Dec 8, 2010
I've read a lot on this, but am having a hard time thinking through this tonight. (Maybe it's the hydrocodone... just had a root canal. i'm just starting on a class to handle client connections to a TCP server. Here is the code I've written thus far:
[Code]...
Now, on my Socket property, when setting the value, it is required to be ByVal. It is my understanding that the instance in memory is copied, and this new instance is passed to value, and my code sets _Socket to reference this instance in memory. Yes?
If this is true, then I can't see why I would want to use properties for anything but native types. I'd imagine there can be quite a performance hit if copying class instances with lots of members. Also, for this code in particular, I'd imagine a copied socket instance wouldn't really work, but I haven't tested it yet.
View 3 Replies
Nov 1, 2010
I have a button that when clicked, creates an instance of a new form and assigns a value to .tag. I have the following code:
Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
If Me.Tag = "NBI" Then
Dim NBIForm As New frmNewNBI
[code]....
View 5 Replies
Sep 9, 2009
I would need some clarification on a syntax : could someone tell me why some people in their code use the following :
If Not (xxx And yyy) = 0 Then
'code
End if
instead of
If xxx = true Then
'code
End if
As an exemple : In a code I use for a listview Item Ownerdraw, it sure works like this :
If Not (e.State And ListViewItemStates.Selected) = 0 Then
' draw the listview item code
End If
but not like this :
If e.State = ListViewItemStates.Selected Then
'
End If
View 3 Replies
Mar 13, 2012
Okay, I was doing a lot of research this morning and found what I hope to be a promising example (code and installation file in the zip folder I downloaded). Even though it is from 2005, and I am working with 2010.I had to update/upgrade the entire project to view the code, and... ok, I am just rambling.I know how to set the filters for SaveDialog and OpenDialog (took me a long while to understand, but I now understand it), but when I finish and build the project to host it on CNet Download or somewhere similar.
View 3 Replies
Feb 29, 2012
I am trying to do my sorts such as bubble sort and quick sort i got the bubble sort to work but cant seem to get the quick sort to work.
CODE:
View 2 Replies
May 13, 2010
I have a RichTextBox where I expect 100 characters per line. Each line can start with the letter A, B, or C. I may have thousands of lines and most of them will start with the letter C.When the cursor is moved from one line to another and is placed on a "C" line, I need to be able to quickly locate the nearest "B" line above it. It may be hundreds of lines away. A loop to search for the "B" line using GetFirstCharIndexFromLine(x) is too slow.
The user may want to paste many lines into the textbox. If necessary, a mild wait after pasting is acceptable.Do you have any suggestions for a technique to accomplish what I need to do? Even just a high level suggestion like "use a linked list"
View 4 Replies
Aug 2, 2010
Could anybody guide me how to perform a quick serch in vb.net database?I used to do it in vb6, using FindFirst method.Is anything else like that in vb.net?Do i always have to use SQL to check if record under current data exists in the database or not?
View 3 Replies
Nov 12, 2009
I used to write programs in Quick Basic on my XP computer. I now have a Vista (64bit) computer and everybody knows (except me) that those programs won't run on my Vista computer.I want to be able to write single user programs on my Vista computer like I did with my XP computer. Since I'm somewhat familiar with the Quick Basic language, I want to stay in the "Basic" language family. What do I need to have on my Vista computer that would allow me to write and run simple single user programs?
View 4 Replies
Jul 19, 2010
I have a list with a boolean value as one of the properties. I need to check if every one of these is true. Now normally LINQ would give a nice clean answer here, but as I am using .NET 2.0 I can't use that.If there a nicer way to do this or am I going to have to do a for each loop and break out on finding a false?
Edit:Seems I could have been a bit clearer. I have an object in a list (eg List (Of MyObject)). There is a boolean property on this object called Processed.I need to check that all objects in the list are processed.So in LINQ I'd do:if (from o in list where o.processed = false select o).count = 0 then....
View 3 Replies
Aug 4, 2010
Decided to make my own installer. code for making a quick launch icon.This is the code im using for creating a desktop icon.
vb.net
Dim WshShell As WshShellClass = New WshShellClass
Dim MyShortcut As IWshRuntimeLibrary.IWshShortcut
' The shortcut will be created on the desktop
[code]....
View 4 Replies
Jun 19, 2009
As a measure of emergency I need to prepare a very simple ActiveX object to be used in Excel sheet and VBA.I'm not a hardcore programmer myself but I'm able to put together a code in VBA to get things done. I have no experience compiling ActiveX dll's in VB though.Could anyone point me to a simple tutorial on the web where I could learn steps how to do it in VB? (project type, setting up methods for the control, parameters for compiling the dll so it's recognized as an ActiveX.. etc)The ActiveX object will be very simple - it's a stopwatch:
1. displaying elapsing time, I have it done already in VB as a windows ap.
2. As an object it will be taking only 3 types of methods: start, stop, reset
3. it has to be a proper ActiveX, so I can use "insert ActiveX" in Excel to add it to the sheet and the code.
I guess I have to start with creating a 'class library' project, haven't I ?
View 5 Replies
May 26, 2011
I am wondering how can I show a balloon tip for my system tray NotifyIcon application QUICKLY. What I mean by quickly is not linger around for like 5 seconds.. I have tried entering 1. For example my code is currently:
NotifyIcon1.ShowBalloonTip(1)
I thought about trying decimals but if I remember correctly from C++ it does nto work or make a difference.. how to display a balloon tip that pops up for only 1 second then dissapears very fast?
View 7 Replies
Nov 4, 2010
The last app I put together was back when .net had just come out around 2002.Ive dusted off my cd's as I need another app writen.The problen is im now running Vista 64bit OS and my Visual Studio.net 2002 cd's are not likeing it at all.Does any1 have a quick fix apart from getting a new version of Visual Studio?Im reloading an old laptop back to XP atm to get a start on the app but would really like it on my main comp.And I dont want to run it in a sandbox either.
View 2 Replies
Jul 5, 2009
I have to parse through a text file that is growing and currently is about 30MB, but it takes a long time for the stream reader to load it before It can loop through the lines. Is there a faster method other than the streamreader?
View 2 Replies
May 16, 2012
Is It possible to make quick selection tool in vb.net like in photoshop?if not can you tell me how to make a free selector or rectangular selector please?
View 6 Replies
Dec 24, 2009
Ran across a snippet a while back but can't seem to find it again. Was very short and simple and detected all versions using version major and minor.
View 4 Replies
Aug 29, 2011
Okay, I've been at this ALL DAY no one's advice has helped so I'm zipping up the simplest version of my problem and attaching it a silver dollar for anyone who wants a quick and (seemingly) easy problem. What it is:
frm1 loads with a button to start frm2(and populate a datagridview).I'm trying to save its data in the module in the example but it might not be necessary.Then another button closes/hides form2 and you can push a button on form 1 to TRY TO get the frm2.datagridview1.item(0,0).value.I can't do any more tonight.
View 6 Replies
Jan 7, 2012
I have a filled dataset from a query.
I must modify 2 columns in this dataset, based on a custom function value (a normal vb function), which parameter is an another column from the dataset.[code]...
View 3 Replies
Feb 12, 2010
I am rather familiar with the ins and outs of VB.NET and Database Selects, Updates and Inserts. Not so good with Transactions. (Oracle, MSSQL)
for example, take a Billing System for a hardware store.I create a 'New Order' and select the Cash Customer I start adding items to this order. 1 Rake 1 Shovel Where do I store this information (temporarily) until the user hits 'SAVE'. Maybe the customer decides they don't want the items. Too expensive. I just EXIT. nothign to do.
Or - I open an existing order and make a bunch of changes. Where do I put these changes until the user hits SAVE. I am sure transactions might have something to do with this - or temporary somethings??? I just don't know and need some guidance.
View 7 Replies
Sep 17, 2010
What's the best/quick way to print a pdf file? The user in the gui only needs to select the pdf and set the printer settings...
View 3 Replies
Jan 6, 2010
Really small and quick question:When i have a listview, with detail view mode. Say i have like 5 columns.
When i select one item in one column, it only selects that item in that specific column i clicked, like a cell
View 2 Replies
Nov 14, 2011
I have a table that has 9 columns, this table has about 5000 rows, but sometimes the user need to update the data in the table. The new data is in another table, with different columns names and only with 8 columns, the ninth column it's the date of the update (i know that this columns shouldn't be here...).
So for now i'm filing one datatable (the data come form a webservice that returns a dataset with this table), and after that i clean the original table and then for each row in the new datatable i call the insert command.Is there other way, better way, to do this?
View 10 Replies