|
Didn't find anything on thread pool on GotDotNet!
Thanks for the reply though! I'm getting around to your comment in the XmlDataEditor, by the way!
Marc
Help! I'm an AI running around in someone's f*cked up universe simulator. Sensitivity and ethnic diversity means celebrating difference, not hiding from it. - Christian Graus Every line of code is a liability - Taka Muraoka Microsoft deliberately adds arbitrary layers of complexity to make it difficult to deliver Windows features on non-Windows platforms--Microsoft's "Halloween files"
|
|
|
|
|
Marc Clifton wrote:
Didn't find anything on thread pool on GotDotNet!
I did http://www.gotdotnet.com/community/usersamples/Default.aspx?query=ManagedThreadPool[^]
Marc Clifton wrote:
I'm getting around to your comment in the XmlDataEditor, by the way!
That one with the questions marks is funny though. It appears when the XML is UTF-8 it gets ?'s but with UTF-16 (thats what u had?) it wouldnt load without removing them first.
I'll mail you a small app to show what i mean.
CHeers
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
I did
Excellent! I tried a variety of search patterns on GotDotNet and never found _any_ articles on thread pools, etc.
I just finished looking at the code--it looks really good. Unlike what I've been able to glean out of .NET's ThreadPool documentation (which is abysmal) it seems that it runs all working threads simultaneously, which is what I want. .NET's ThreadPool implied that only one thread was active at a time, which is not what I want. Because the documentation is so sparse and the terminology is confusing, I'm going to need to test this all out.
It appears when the XML is UTF-8 it gets ?'s but with UTF-16 (thats what u had?) it wouldnt load without removing them first.
Argh. I struggled with this UTF-8 and 16 thing. If I used .NET's default, then the generated XML was unreadable in something like notepad, which I needed in debugging. Maybe I should make it an option as to the XML format. It seems that it usually can't figure it out on its own either when reading an XML document.
In other words, it's a mess and I didn't pay a lot of attention to it except to scream at it until I got what I needed.
Marc
Help! I'm an AI running around in someone's f*cked up universe simulator. Sensitivity and ethnic diversity means celebrating difference, not hiding from it. - Christian Graus Every line of code is a liability - Taka Muraoka Microsoft deliberately adds arbitrary layers of complexity to make it difficult to deliver Windows features on non-Windows platforms--Microsoft's "Halloween files"
|
|
|
|
|
As far as I understand, System.ThreadPool is actually running one thread at a time PER CPU. For most cases, this is the same as one thread at a time. But also according to my understanding, there are multiple worker threads (up to 25 by the default limit) that are all running at the same time, but a worker thread is unlikely to give up its timeslice without a sleep() call or something similar.
I've found System.ThreadPool fairly reasonable for my non-trivial needs. One complaint I had was not being able to stop worker threads, but that hasn't posed a problem in my project yet. My major concern with System.ThreadPool is that it might not be supported with Windows 98, and if that's the case, I'll move to ManagedThreadPool or the DevelopMentor.ThreadPool published on CodeProject.
|
|
|
|
|
Hi,
which methods or namespace i have to use if i like to deal with relative and absolute path ?
i like to use relative path's to a given absolute path
.:Greets from Jerry Maguire:.
|
|
|
|
|
Does System.IO.Path.Combine help?
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Hi,
i need it vice versa
i have two absolute paths and like to have the relative path from path1 to path 2, like it's in web hyperlinks.
Any clues ?
.:Greets from Jerry Maguire:.
|
|
|
|
|
Jerry Maguire wrote:
i have two absolute paths and like to have the relative path from path1 to path 2
Ok, I think the easiest thing to do is to break each part down (root, dir, dir, ..., filename) then you can start to remove the like parts one by one until they don't match.
path1 => "/foo/bar/baz/index.html"
path2 => "/foo/bar/stuff/kappa.html"
path1 breakdown:
root = "/"
dir = "foo", "bar", "baz"
filename = "index.html"
path2 breakdown:
root = "/"
dir = "foo", "bar", "stuff"
filename = "kappa.html" Now to generate the relative path...
path1.root == path2.root so remove the root from the list
path1.dir[0] == path2.dir[0] so remove that from the list
path1.dir[1 (really 0 now)] == path2.dir[1 (ditto)] so remove that from the list
path1.dir[2 (really 0 now)] != path2.dir[2 (ditto)] so we can begin to piece together the relative path.
For each directory left in path1 you need to go up one directory (..) then append each of the directories left in path2.
If by chance you have found that all of the directories match then you just need to specify the filename. I'll work up some code then post it as a reply to this msg
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
OK, I've got the code written
It will probably cause scrolling here, but I've uploaded a text file to my webserver for copy/paste purposes.
http://www.takklesoft.com/GetRelativePath.cs.txt[^]
public string GetRelativePath(string path1, string path2)
{
return GetRelativePath(path1, path2, false, System.IO.Path.DirectorySeparatorChar);
}
public string GetRelativePath(string path1, string path2, bool enableWebChecking)
{
char seperator;
if( enableWebChecking )
seperator = '/';
else
seperator = System.IO.Path.DirectorySeparatorChar;
return GetRelativePath(path1, path2, enableWebChecking, seperator);
}
public string GetRelativePath(string path1, string path2, bool enableWebChecking, char dirSeperator)
{
System.Text.StringBuilder relativePath = new System.Text.StringBuilder();
System.Collections.Specialized.StringCollection path1Dirs;
System.Collections.Specialized.StringCollection path2Dirs;
path1Dirs = new System.Collections.Specialized.StringCollection();
path1Dirs.AddRange(path1.Split( new char [] { dirSeperator } ) );
path2Dirs = new System.Collections.Specialized.StringCollection();
path2Dirs.AddRange(path2.Split( new char [] { dirSeperator } ) );
string path1Root = "";
string path2Root = "";
if( !path1.StartsWith(dirSeperator.ToString()) )
{
path1Root = path1Dirs[0] + dirSeperator.ToString();
path1Dirs.RemoveAt(0);
}
if( !path2.StartsWith(dirSeperator.ToString()) )
{
path2Root = path2Dirs[0] + dirSeperator.ToString();
path2Dirs.RemoveAt(0);
}
if( enableWebChecking )
{
path1Root += path1Dirs[0] + dirSeperator.ToString();
path1Dirs.RemoveAt(0);
path1Root += path1Dirs[0] + dirSeperator.ToString();
path1Dirs.RemoveAt(0);
path2Root += path2Dirs[0] + dirSeperator.ToString();
path2Dirs.RemoveAt(0);
path2Root += path2Dirs[0] + dirSeperator.ToString();
path2Dirs.RemoveAt(0);
}
if( path1Root != path2Root )
return path2;
string filename = "";
path1Dirs.RemoveAt( path1Dirs.Count - 1 );
filename = path2Dirs[ path2Dirs.Count - 1 ];
path2Dirs.RemoveAt( path2Dirs.Count - 1 );
while(
path1Dirs.Count > 0 &&
path2Dirs.Count > 0 &&
path1Dirs[0] == path2Dirs[0] )
{
path1Dirs.RemoveAt(0);
path2Dirs.RemoveAt(0);
}
while( path1Dirs.Count > 0 )
{
relativePath.Append(".." + dirSeperator);
path1Dirs.RemoveAt( 0 );
}
while( path2Dirs.Count > 0 )
{
relativePath.Append(path2Dirs[0] + dirSeperator);
path2Dirs.RemoveAt( 0 );
}
relativePath.Append( filename );
return relativePath.ToString();
} Almost everything I threw at it came out correct so it should work fine for you. [edit]Added a web checking mode so that it properly works on fully qualified URLs (needing the http:// stuff) There is one problem though in that if you use a fully qualified URL on two different servers it won't work correctly (say http://www.foo.com/bar.html and http://www.bar.com/baz.html will return ../../www.bar.com/baz.html .[/edit]
I didn't want to go from fairly generic code to include specific cases so I left it alone, though a quick fix could be added (and I may work on that now )
An enhancement I can think of would be to be smart about creating the relative path. Like if the two absolute paths are /foo/blah/a.html and /b.html have it return /b.html rather than ../../b.html .
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Hi,
wow great, thank you
i check it out...
.:Greets from Jerry Maguire:.
|
|
|
|
|
hello everyone,
i have a question, can i convert a bitmap object or any image object to an array of bytes, in order to send it over a LAN ??!!!
if yes, plz tell me how to do it.
P.S. i need this piece of info urgently for my graduation project )
thanks a lot,
bye
|
|
|
|
|
The best way would be saving it directly on the network stream.
|
|
|
|
|
Hi Dalia,
Use the Save method of the Image /Bitmap to save it into a MemoryStream and then open the stream and read it into a byte array.
Hope that helps
Smitha
The future belongs to those who believe in the beauty of their dreams.
--Eleanor Roosevelt
|
|
|
|
|
thanks a lot )
i'm going to try it
|
|
|
|
|
Hi!
I created an appliction with C# to display a large mount of text.
I thought richtextbox control might be a nice choice, but it seems it is not.
I wote my code like this:
public void AppendText(string myMessage)
{
this.richtextbox1.AppendText(myMessage);
}
When I ran my simulation, I got more than 2000 messages coming all the time. Each message is about 2 - 30 rows. The code doesn't work when those 2000 messages were coming. My application was just hanging there and took 100% of CPU.
Then I tried with InvokeMember(). I created a new class called MessageWriter which has a static method called
WriteMessage(string msg). In my form, I changed the code to:
public void AppendText(string myMessage)
{
Type myType = typeof(MessageWriter);
myType.InvokeMember("WriteMessage", BindingFlags.InvokeMethod, null, null, new object[]{myMessage, this.richtextbox1});
}
public static void WriteMessage(string msg, RichTextBox rtb)
{
rtb.AppendText(msg);
}
But unfortunately, this code doesn't work neither. Updating of the richtextbox is far too slow. My application has no time to do anything else.
How can I make richtextbox to update itself quickly! How can I solve this problem?
I am looking forward for your suggestion.
Best regars
Maruko
|
|
|
|
|
Maruko S wrote:
When I ran my simulation, I got more than 2000 messages coming all the time. Each message is about 2 - 30 rows. The code doesn't work when those 2000 messages were coming. My application was just hanging there and took 100% of CPU.
With good reason, you aren't letting the app do anything else. If you want to get some small bit of responsiveness you need to let the application process other messages. To do this put in some calls to Application.DoEvents() in your loop that is processing those 2000 messages.
Maruko S wrote:
Then I tried with InvokeMember().
InvokeMember is just going to slow it down even more, at worst you're incurring another lookup to find the WriteMessage method, at best you have another layer to go through to do make the call to the RichText box's AppendText method.
Maruko S wrote:
How can I make richtextbox to update itself quickly!
My suggestion...batch some of those updates together. Rather than updating 100 times a second (far faster than most people can comprehend) update 3-4 times a second. You can also try Application.DoEvents as I described above.
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Hi!
Can anyone please verify that this is indeed a VS .NET bug?
Recipee:
Create a C# Windows Forms project
Add a Menu with a few items
Add an AxMediaPlayer (COM Component)
Place it inside a panel
Bug:
The IDE does not run the Menu. F5 creates the app but
not the menu. In design time, if you click on the Menu icon
in the guiless items tray (bottom), the Form shows the menu.
Click on the form and the menu disapear.
Is it me, heh ???
Thanks !
Antoine
|
|
|
|
|
Some calendars are not supplied in .NET framework.Can somebody guide me ,How to implement custom calender,Any article or library or suggestion?
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
http://www.codeguru.com/forum/showthread.php?s=&postid=746030#post746030
|
|
|
|
|
i have a standard treeview control with checkboxes, how can i check all the children of a node when the parent is checked? i already have events for before and after check so i assume it must go in there but the problem i have is finding which node is selected as a node doesn't have to be selected for it to be checked.
Does anyone have any ideas as its really starting to annoy me as i know it must be so simple
Thanks
|
|
|
|
|
fixed it, i use e.Node to get the children and as its in the event afterCheck, it acts recursively to check all the children!
|
|
|
|
|
check this
TreeView, by recursion you can check anything you want
http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=b650f7fb-147d-4326-8d83-cb51d89a4ca5
|
|
|
|
|
OpenFileDialog type:
I am trying to send Intel hex file to target memory to one of my hardware .
I add (buttonOpenFile) in one of my application to send a file (SendFile) .
The code look like one below.
public void SendFile(FileStream fs)
{
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, (int)fs.Length);
Send(buffer);
}
Now I put the following in my button click handler:
private void buttonOpen_Click(object sender, System.EventArgs e)
{
FileStream fileh = new FileStream(@"C:\Skole\p01.hex", FileMode.Open, FileAccess.Read);
BaseTerm.term.SendFile(fileh);
fileh.Close();
}
The above code work without any problem, but I wish to create an instance of System.Windows .Form OpenFileDialog type
to return a Stream that represents the specified file selected by the user.
--------------------------------------------------------------------------------------
I tried to write the code to do the job, but I do not know how to write the last pieces of code.
I will be grateful if you could help me.
private void buttonOpen_Click(object sender, System.EventArgs e)
{
OpenFileDialog myOpenFileDialog = new OpenFileDialog();
myOpenFileDialog.InitialDirectory = "c:\\Skole\\" ;
myOpenFileDialog.Filter = "hex files (*.hex)|*.hex|All files (*.*)|*.*" ;
myOpenFileDialog.FilterIndex = 1 ;
myOpenFileDialog.RestoreDirectory = true ;
if(myOpenFileDialog.ShowDialog() == DialogResult.OK)
{
Stream myStream = null;
if(( myStream = myOpenFileDialog.OpenFile()) != null)
{
??????????
??????????
}
}
}
Salam Hamid
|
|
|
|
|
Change SendFile to accept a Stream type instead of a FileStream type. Then, pass the stream object received from the dialog-use code.
John :D
|
|
|
|
|
Thanks John it works finally..
Salam
|
|
|
|