Questions tagged [disposing]

16 questions
11
votes
1 answer

JavaFX IllegalStateException when disposing JFXPanel in Swing

I've just come across an oddity with JavaFX and Swing. When disposing a JavaFX Panel that had been added to a JFrame or JPanel, re-adding a new JFXPanel will throw an IllegalStateException: "Platform.exit has been called". In my case this has…
TomDK
  • 1,163
  • 9
  • 16
7
votes
4 answers

Passing IDisposable as a parameter

Is it a good practice to pass IDisposable as a parameter to a method and dispose it inside that method. This is sort of inevitable when you have to use several threads. Well, the best practices says the owner(caller) should dispose it. E.g. public…
Sriwantha Attanayake
  • 6,943
  • 4
  • 37
  • 44
5
votes
3 answers

Anonymous event handlers and disposing

I have a rather short question about anonymous event handlers: This is the code that I have: public void AddTestControl(Control ctrl) { ctrl.Disposed += (o, e) => { RemoveTestControl(ctrl); }; ctrl.SomeEvent += _Control_SomeEvent; } public…
juFo
  • 15,486
  • 9
  • 90
  • 128
4
votes
2 answers

Difference between Old generation and Tenured generation

Now I trying to understand fundamental concepts of java garbage collection. I have read a lot articles about it. And somewhere I see old generation and somewhere tenured generation. Description is very similar. looks like one of them is the…
gstackoverflow
  • 31,683
  • 83
  • 267
  • 574
3
votes
1 answer

Disposing managed resources in WPF Custom Controls

I'm writing some WPF custom controls for a third part library. For instance I enhanced the standard ComboBox with some dependency properties. The main problem is that my controls have as private instances some IDisposable objects, and I'd like to…
2
votes
5 answers

Is there any case where we have to set variables to null in C# when disposing them?

If the variable is local to the current scope, is there any reason to set them to null right before the end of it? { var com = new AComponentObjectModelInterface(); // something goes here // ... com = null; // why? }
Jader Dias
  • 81,082
  • 147
  • 410
  • 611
2
votes
2 answers

Do I have to manually remove all event handlers for each instance?

Consider this class: Class Item : Inherits ItemBase Public Sub New AddHandler MyEvent, AddressOf MyEventHandler End Sub Private Sub MyEventHandler() End Sub Private Sub MySecondEventHandler() Handles…
Shimmy Weitzhandler
  • 92,920
  • 119
  • 388
  • 596
1
vote
1 answer

If Form1 opens Form2 and registers for Form2.TextChanged, do I need to unregister Form2.TextChanged from within Form1 if Form2 is closing?

This is another question about well disposing objects from .NET. After having read a lot of different arcticles about dispose best practices (and people opinions), I was not able to get an answer for that one. I have 2 forms, Form1 and…
Benoit Drapeau
  • 614
  • 1
  • 6
  • 13
1
vote
3 answers

Disposing connection, command, adapter

When I am querying the database from my c# code I usually use something like this construction: using (var connection = new OleDbConnection(connStr)) using (var command = new OleDbCommand(query, connection)) using (var adapter = new…
Arsen
  • 23
  • 3
1
vote
2 answers

Disposing JFrame by clicking from an inner JPanel

I'm trying to dispose my JFrame by clicking a button, located on a JPanel that is placed on the JFrame that I want to close. I tried to make a static method on the JFrame class, but ofcourse my IDE told me that wasn't going to happen. Anyone…
Jeroen
  • 131
  • 2
  • 12
1
vote
2 answers

Right way of using Backgroundworker

I'm using a backgroundworker for showing a loadingscreen. The DO-event looks as follow: private void bwLoadingScreen_DoWork(object sender, DoWorkEventArgs e) { _ls = new LoadingScreen(); _ls.Show(); while…
Max
  • 11,136
  • 15
  • 65
  • 92
1
vote
1 answer

Can I control cleaning items when user leaves the request?

I have a page that allows uploading of multiple files, the files are uploaded constantly, i.e. there are many FileUpload controls and a submit button near each of them and it uploads immediately. I want, that once the user leaves the page and goes…
Shimmy Weitzhandler
  • 92,920
  • 119
  • 388
  • 596
0
votes
1 answer

C# How do I prevent a TcpClient object from disposing in a different thread i've created with the new keyword?

So I'm trying to make a client for my server in C#, that accepts messages as commands so I can control the client remotely. I've had problem after problem with my masterServer.Connect taking FOREVER to load, and almost every time I close my…
OneShot
  • 581
  • 7
  • 19
  • 31
0
votes
2 answers

XNA - How to make an image disappear after x seconds?

Sorry to bother everyone, I can't find any good tutorials on XNA so I just come here for help, so how do you make it wait before disposing? protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Black); …
TheQuantumBros
  • 308
  • 2
  • 4
  • 16
0
votes
6 answers

using Multiple using statements to dispose DataSet and DataTables

Can you please explain what is happening here? using(DataSet ds = GetDataSet()) // will this get disposed? if yes (when?) { using(DataTable dt = ds.Tables[0]) /* in this line is ds available for dt? i found some issue with this kind of…
Rakesh
  • 313
  • 4
  • 21
1
2