Comments (2)
creation date = 2009-03-04T10:48:35.51-08:00
I've experienced these quite alot some time ago... my solution for fixing it was implementing a pool of threads. In my app there are about 7-8 concurrent threads and some of course will require access to the UI.
When working with the tree from another thread you should go for something like if (this.InvokeRequired) ... and use BeginUpdate() and EndUpdate() when using data from the tree.
This is my ThreadMgr class, feel free to adapt it to your needs.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Collections;
namespace LUR.Interop
{
public class ThreadMgr : IDisposable, IEnumerable
{
private List<Thread> Pool = null;
public ThreadMgr()
{
Pool = new List<Thread>();
}
public int Clean()
{
int Running = 0;
if (Pool == null)
return Running;
for (int i = 0; i < Pool.Count; i++)
{
if (Pool[i].IsAlive)
Running++;
else
Pool.Remove(Pool[i--]);
}
return Running;
}
public bool this[string Item, ThreadStart x]
{
set
{
Thread t = this[Item];
if (t == null)
{
try
{
if (x == null)
throw new System.ArgumentNullException();
t = this[Item] = new Thread(x);
t.TrySetApartmentState(ApartmentState.MTA);
if (value)
t.Start();
}
catch (System.ArgumentNullException)
{
Console.WriteLine("ThreadMgr: null or malformed parameterized thread start invoked.");
}
catch (System.Threading.ThreadStateException msg)
{
Console.WriteLine("ThreadMgr: failed " + msg.Message + " at " + msg.Source + " in " + Item + " context");
}
catch (Exception msg)
{
Console.WriteLine("ThreadMgr: unrecoverable fault caused by " + msg.Message + " in " + msg.StackTrace);
}
}
else
{
// Ionutz: testeaza-ma!
MessageBox.Show(null, Item + " context is already locked or request is null; cannot instanciate.\n" +
"You may be trying to re-execute the same operation before waiting the previous attempt to complete",
"Threading Manager", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}
public Thread this[string Item]
{
get
{
if ((Pool != null) && (Pool.Count > 0))
{
foreach (Thread t in Pool)
if (t.Name == Item)
return t;
}
return null;
}
set
{
if (Pool == null)
Pool = new List<Thread>();
try
{
Pool.Add(value);
value.Name = Item;
}
catch (Exception msg)
{
Console.WriteLine("ThreadMgr: " + msg.Message + "; " + value.Name + " override attempt with " + Item + " denied.");
}
}
}
public void Sync(string Item)
{
Thread t = this[Item];
try
{
if (t.IsAlive)
t.Join();
}
catch { }
}
#region IDisposable Members
public void Dispose()
{
if ((Pool != null) && (Pool.Count > 0))
{
for (int i = 0; i < Pool.Count; i++)
{
if (Pool[i].IsAlive)
Pool[i].Abort();
Pool.Remove(Pool[i--]);
}
}
}
#endregion
public void Recycle(string id)
{
try
{
foreach (Thread Pooled in Pool)
{
if (Pooled.Name.Contains(id))
{
Pooled.Abort();
break;
}
}
}
catch
{ }
}
#region IEnumerable Members
public IEnumerator GetEnumerator()
{
foreach (Thread t in Pool)
{
yield return t;
}
}
#endregion
}
}
from anolis.
closed date = 2009-04-10T14:29:58.64-07:00
I solved this by making the PopulateResourceType method check if the .CancelAsync method had been called. Additionally there are two layers of threads from ShowResourceType and PopulateResourceType.
from anolis.
Related Issues (20)
- Image centering is buggy HOT 2
- x64 Control may not support transparent background colors HOT 4
- Worker thread does not stop if tree selection changes HOT 1
- RawViewer.RenderResource creates lag with large arrays HOT 1
- Rename Anolis.Gui, build "blind mode", and improve Icon resource handling HOT 1
- Serious GDI+ Handle Leakage HOT 1
- Tree view contents duplicated on save HOT 1
- Use Finalizers HOT 1
- 'Back' button error: "The file "" does not exist" HOT 2
- Restart bug HOT 1
- MSStyles editing at the level of Ave's Vista Style builder (a little side thing; improvement/ feature suggestion) HOT 1
- Fix wizard scaling HOT 1
- crash when changing size of toolbar icons HOT 2
- Add RES/RC Support HOT 2
- ResourceListView - Threading issues again HOT 1
- Damage mitigation HOT 1
- Issue when replacing bitmaps in explorer.exe (Win7 rtm x64)
- Version resource not handled properly
- Feature Request: Batch Import
- Download filename should contain "anolis"
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from anolis.