|
Yes you seems to be right I tested it, and it really lives as long as the thread lives. However
I run in exactly this problem someday where the gc killed thread objects, which I had to force to be
at least an object with a mid-ranged lifetime-cycle otherwise the app chrashed after a while.
So I thought this can be a reason, but it wasn't.
To your solution: I only worked one time with ThreadPools, after that I loved it to do this on my own.
[edit] did some typo
Greetings
Covean
|
|
|
|
|
Hi,
I think your problem is in using the ThreadPool.
The TP holds a large number of threads, and has a queue into which you can insert jobs. Now those jobs get executed by some number of TP threads; however that number does not equal the number of available jobs: it starts of at a few only, and will grow and shrink using a complex algorithm. In one of my experiments I noted it only grows at a rate of 2 per second. Therefore your jobs will queue up and wait on others to finish first, which is not what a normal server does (it either accepts the job or refuses it, but never postpones it).
So IMO you should use either real Threads or (more unlikely to succeed) use asynchronous operations. BackgroundWorkers would not help as they run on the TP as well.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Ok, thanks a lot all for your answers.
So I think the summary of the situation concerning multithreading in C# is (correct me if I'm wrong):
- use asynchronous requests and let the system handle the multithreading; (1)
- use threadPool and let the system handle the multitreading (distribute tasks among worker threads); (2)
- implement "real" multi threading, handling synchronization, locks, etc; (3)
I wanted to keep it as simple as possible, without having to write a lot of "thread" of code (unless absolutely necessary), so I tried to stick to option (2), which as Luc Pattyn mentioned, has some limitations but I think I can "live" with them (that is, the app fails sometimes, I can catch the errors and carry on without major implications for the user).
One thing that I amended in my code, was removing the "restart" of the listener on the event of an exception; there is no need to stop and start the listener on error, and in fact, when I had a lot of threads running, the "restart" of the listener itself was a cause of problems...
The I/O operation has been aborted because of either a thread exit or an application request
So, after refactoring my "ProcessRequest" callback, it now looks like this: no restart of the listener and separate handling of different types of exceptions; one important thing is to close the Context.Response after an error, so that it sends a response to the client;
private void ProcessRequest(object listenerContext)
{
try
{
byte[] buffer;
var context = (HttpListenerContext)listenerContext;
try
{
Uri aUri = context.Request.Url;
string url = aUri.AbsolutePath + aUri.Query;
System.Uri uri = m_service.GetUri();
string address = uri.Scheme + "://" + uri.Host + ":" + uri.Port + url;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address);
instream.Close();
outstream.Close();
context.Response.OutputStream.Close();
}
catch (System.ArgumentException ex)
{
context.Response.StatusCode = int.Parse(ex.Message);
context.Response.StatusDescription = GetStatusDescription(context.Response.StatusCode);
byte[] buff = System.Text.Encoding.UTF8.GetBytes("<HTML><BODY><b>Proxy Failure:</b> (" +
context.Response.StatusCode + ") " + context.Response.StatusDescription + "</HTML></BODY>");
context.Response.ContentLength64 = buff.Length;
context.Response.OutputStream.Write(buff, 0, buff.Length);
}
catch (System.Net.HttpListenerException ex) { }
catch (System.Net.WebException ex)
{
int status = (int)((HttpWebResponse)ex.Response).StatusCode;
context.Response.StatusCode = status;
context.Response.StatusDescription = GetStatusDescription(status);
context.Response.Close();
}
catch (Exception ex) { }
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
}
It's not the best solution, has it fails to deliver some jobs (not properly handling the multithreading), but its kind of working and is simple.
cheers,
Jo
|
|
|
|
|
Hai all
I would like to know how i can convert office 2003(.doc) to pdf using some open source library dll's. I was successful in converting office 2007 files to pdf. I used different opensource dlls like itextsharp,sharppdf etc... but they wont take any .doc files for conversion. We can only create an entirely new pdf document out of it.
Friends any help is greatly appreciated...
I was behind it for quite amount of time
Thnx n advance...
Santo
Santhosh
|
|
|
|
|
I display some jpeg images loaded from Stream object in dynamicly created PictureBox component.
void function(Strean jpegStream)
{
Bitmap img = new Bitmap(jpegStream);
}
While 96dpi images are displayed correctly, some of the non 96dpi jpegs, e.g. 72dpi, 480dpi which come from photoshop or digital cameras get corrupted after I attach them to Image property of the PictureBox component and they are displayed.
As though half of the jpeg or more were not decompressed, leaving bottom half of the image grayish.
However if I delete and create again PictureBox component, and attach the same Bitmap object img again, already created from jpeg stream, they are correctly displayed???
Чесноков
|
|
|
|
|
Erhm, it seems there's no problem with the dpi's but more with the files itself. Your JPEG compression may be corrupt or something, but I would say the JPEG compression method is not great.
|
|
|
|
|
Hi guys.
We're trying to implement a centralized configuration for all .net applications and by so we have created a master configuration at a specific location. We're then creating a custom configuration manager that uses both the local app.config and the centralized master configuration.
The master configuration is read using System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(string path, UserLevel level).
The appSettings section and all other custom sections are read and available but our problem occurs when we try to read the sections from the master configuration using ConfigurationManager.GetSection(string sectionName).
We get a TypeLoadException no matter what type of section handlers we use - .NET handlers or custom handlers, and the method returns a System.Configuration.DefaultSection object instead of the intended type.
Could not load type 'System.Configuration.NameValueSectionHandler' from assembly 'System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Reading the same sections from the app.config of the exectuable produces no errors.
Anybody with some ideas as to what causes the problem?
-Larantz
for those about to code, we salute youPlease refer to the Forum Guidelines for appropriate posting.
|
|
|
|
|
The type System.Configuration.NameValueSectionHandler is in the System.Configuration namespace but it is actually defined in System.dll and not System.Configuration.dll as you might assume, so change your configuration section to
<section name="" type="System.Configuration.NameValueSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
and it should work.
|
|
|
|
|
I'll try that.
Thanks for the tip.
-Larantz
for those about to code, we salute youPlease refer to the Forum Guidelines for appropriate posting.
|
|
|
|
|
It seems that the section handler did load so the TypeLoadException is gone.
But instead of actually returning a NameValueCollection - it still just returns a System.Configuration.DefaultSection which is useless.
I just can't get my head around why this is occurring.
It's the same for custom section handlers.
-Larantz
for those about to code, we salute youPlease refer to the Forum Guidelines for appropriate posting.
|
|
|
|
|
|
Well that sure answers it.
I'll have a look at the document mentioned there.
Thanks mate!
-Larantz
for those about to code, we salute youPlease refer to the Forum Guidelines for appropriate posting.
|
|
|
|
|
Hi all
I Want To Add row to data grid view
but I Have a Problem
When I Create a DataGridViewRow row=new DataGridViewRow();
and I Set The Row From Grid1 To row
and The Add it To Grid2
But The VS2008 Give Me this Exception
Row provided already belongs to a DataGridView control.
what is the Problem ??
who can Solve it ??
thanks
|
|
|
|
|
Message Closed
modified 23-Nov-14 7:03am.
|
|
|
|
|
This is my code,, i create another row bust stell having the same problem !!
private void GridOne_DoubleClick(object sender, EventArgs e)
{
DataGridViewRow row = new DataGridViewRow();
row = GridOne.Rows[GridOne.CurrentRow.Index];
DataGridViewRow row2 = new DataGridViewRow();
row2 = row;
GridTwo.Rows.Add(row2);
}
i stell get this exception !!
Row provided already belongs to a DataGridView control.
|
|
|
|
|
All you're doing is moving around references and clobbering others.
Read up on the DataGridViewRow.Clone method; which includes an example on how to copy a row and its cell values.
|
|
|
|
|
Rinad wrote: DataGridViewRow row = new DataGridViewRow();
row = GridOne.Rows[GridOne.CurrentRow.Index];
DataGridViewRow row2 = new DataGridViewRow();
row2 = row;
So this is what you're doing:
row = new DataGridViewRow();
row = GridOne.Rows[GridOne.CurrentRow.Index];
DataGridViewRow row2 = new DataGridViewRow();
row2 = row;
the new rows you create are thrown away in the next line!
For copying a DGV row to another DGV what you probably need (I've never done this) is:
1. get the source row
2. clone it
3. add the clone to DGV2
For moving a DGV row to another DGV what you probably need is:
1. get the source row
2. remove it from DGV1
3. add the clone to DGV2
In both cases, there is no new DataGridViewRow() involved (it wouldn't even now how your row is supposed to look).
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Dear all,
I have one base class say BaseOne in that I have 2 methods.One method should not be override by the other method.How can i achive this.
Thanks,
Srinivas Mateti
|
|
|
|
|
I assume you mean that one method can be overridden and the other cannot, as you cannot override a method in the same class. Nothing can stop anyone overloading the method however.
On that assumption mark the overridable method as Virtual and the not overridable one as sealed .
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
www.JacksonSoft.co.uk
|
|
|
|
|
I am extreamly sorry..one method can be override by the child class and the other method should not be override the child class...
Please see the correction and sorry for the mistake.
Thanks,
Srinivas Mateti
|
|
|
|
|
Mark the method you want to override as virtual. And do not mark the other.
Like:
public virtual void OverridableMethod();
public void NonOverridableMethod();
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Thanks for the reply...so from your reply what i understood is
1) Virtual methods should be override by the child class,if the child class doest implement the virtual methods then error will shown up.
2) And only virtual methods can be override by the child class non virual methods can not be implemented by child class
One more q:
Can I again declare virtual method as virtual in child class???
Thanks in advance,
Srinivas Mateti
|
|
|
|
|
sris 426 wrote: if the child class doest implement the virtual methods then error will shown up.
No.
sris 426 wrote: And only virtual methods can be override by the child class non virual methods can not be implemented by child class
Correct. Although I assume you mean overridden when you say implement.
sris 426 wrote: Can I again declare virtual method as virtual in child class???
Yes they can.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
To clarify:
sealed - Specifies that a method cannot be overriden.
abstract - Specifies that a method must be implemented in a derived class.
virtual - Specifies that a member may be overriden, but does not have to be.
Note that if your class includes abstract members then the class itself must also be marked as abstract.
http://www.dnzone.com/go?356[^] lists all the permutations of sealed, abstract etc. for c# and vb.Net.
A virtual method will still be virtual in a sub-class of a sub-class unless you mark is as override sealed in the class in the middle, which then stops classes further down the inheitance tree from overriding that method.
A sub-class can always declare additional methods which may or may not be overridable in turn, as you desire.
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
www.JacksonSoft.co.uk
|
|
|
|
|
Thanks for the reply...
Can I use sealed for methods....? I think I can not use sealed for methods...When declared sealed for methods it gave error...
PLease confirm...
Thanks,
Srinivas Mateti
|
|
|
|