|
Sorry, my reply wasn't very accurate; I should have payed more attention to the details of your code. The way I do such things typically is like so:
public void SetText(Control control, string text) {
if (control.InvokeRequired) {
control.Invoke(new ControlStringConsumer(SetText), new object[]{control, text});
} else {
control.Text=text;
}
}
and then my earlier reply would apply. My "canonical form" as I call it here[^], has the advantage of containing the actual operation code only once.
Your code, which was
if (this.OutputConsole.InvokeRequired) {
this.OutputConsole.Invoke(
new OutputConsoleUpdater(delegate(string s) { this.OutputConsole.AppendText(s + "\r\n"); }),
text);
} else {
this.OutputConsole.AppendText(text + "\r\n");
}
could be simplified to
this.OutputConsole.Invoke(
new OutputConsoleUpdater(delegate(string s) { this.OutputConsole.AppendText(s + "\r\n"); }),
text);
assuming we are NOT on the GUI thread. Using Invoke() it also causes the delegate to be executed on the GUI thread, through Windows messages, implying an automatic sequential treatment.
Now I'm not sure about the lock issue you raised; it may depend on where exactly you put it, and even more on what is inside the OutputConsoleUpdater constructor. But anyway, the conclusion will be there is no need for such a lock.
FWIW: you could break the automatic sequencing by using Application.DoEvents() inside some event handler; that is exactly why doing so is a very bad idea most of the time.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Perfect, the idiom you use is definitely more elegant glad I learned something new today.
As for the deadlock, I'm quite sure why it happens (the "pump" that does the Invoke requests doesn't get called as the whole thread is stuck waiting in the first place), no problems there.
thanks a lot for your time!
|
|
|
|
|
hello.
i am creating a jpeg encoder i need to access a image file.
can u tell me how can i read and write using dll.
getPixel(), setPixel() is very slow.
|
|
|
|
|
Is there a reason you can't use:
Bitmap RawImage = new Bitmap(Filename);
Once it's in the Bitmap, then you can use the pixel buffer for faster access. Google will help with how to do that.
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
|
I have the following classes in Java which i want to convert to C# but have errors with the undelined codes. (Can someone help me with the C# equivalent of PUT and GET)
class TagInfo{
public int tagOffset;
public int tagLength;
public TagInfo(){
}
}
private void buildMetaData()
{
Record record = getData();
int offset = IMGREC_TAGLIST_INDEX;
int numTags = 0 ;
short tagID = 0;
try
{
numTags = this.getNumberOfTags() ;
for (int i=0; i < numTags; i++){
TagInfo info = new TagInfo();
info.tagOffset = offset;
info.tagLength = TagRecord.TAG_DATA_INDEX + record.readInt(offset + TagRecord.TAG_DATALEN_INDEX);
tagID = record.readShort(offset + TagRecord.TAG_ID_INDEX);
offset += info.tagLength;
tagInfo.put(new Short(tagID),info);
Console.WriteLine("tagID = " + tagID);
}
}
catch (Exception ex)
{
}
finally
{
}
this.imageOffset = offset;
this.imageSize = record.getLength() - offset;
}
public TagRecord getTagByID(short id)
{
TagRecord record = null;
TagInfo info = (ImageRecord.TagInfo)tagInfo.get(new Short(id));
if (info != null){
byte[] data = this.getData().read(info.tagOffset,info.tagLength);
record = new TagRecord(data);
}
return record;
}
|
|
|
|
|
Those lines appear to be using a variable which does not exist. What is the type of tagInfo and where does it come from? It isn't a local variable or parameter or even a field in the class - so what is it?
|
|
|
|
|
Not to good at Java, but my understanding is that Put and Get operate on an automaticaly generated parent hashtable of the object in question. c# does not have this at all. You have to create your own dictionary.
This might not be quite right as you did not post the entier code, but the following should help you. Note the dictionary declaration and add/get code. I have used a generic dictionary to enable strong typing.
class TagInfo{
public int tagOffset;
public int tagLength;
public TagInfo(){
}
}
System.Collections.Generic.Dictionary<int, TagInfo>; TagInfoDictionary = new System.Collections.Generic.Dictionary<int, TagInfo>();
private void buildMetaData()
{
Record record = getData();
int offset = IMGREC_TAGLIST_INDEX;
int numTags = 0 ;
short tagID = 0;
try
{
numTags = this.getNumberOfTags() ;
for (int i=0; i < numTags; i++){
TagInfo info = new TagInfo();
info.tagOffset = offset;
info.tagLength = TagRecord.TAG_DATA_INDEX + record.readInt(offset + TagRecord.TAG_DATALEN_INDEX);
tagID = record.readShort(offset + TagRecord.TAG_ID_INDEX);
offset += info.tagLength;
this.TagInfoDictionary.Add(tagID, info);
Console.WriteLine("tagID = " + tagID);
}
}catch (Exception ex){}
finally{}
this.imageOffset = offset;
this.imageSize = record.getLength() - offset;
}
public TagRecord getTagByID(short id)
{
TagRecord record = null;
TagInfo info = this.TagInfoDictionary[id];
if (info != null){
byte[] data = this.getData().read(info.tagOffset,info.tagLength);
record = new TagRecord(data);
}
return record;
}
|
|
|
|
|
hi
what is the equivalent of this code in c#
this code is in VB6
Chr$(Asc("0")
thanks
|
|
|
|
|
Try Convert.ToChar(6); .
The output is a unicode value.
|
|
|
|
|
Apart from lacking a parenthesis, it does not make much sense; Asc() returns a number holding the ASCII value, which is 48 for a zero; and Chr$() does the inverse, it returns the ASCII character equivalent of a numeric value. So they cancel each other, it simply means "0"
In C# we use different delimiters for string literals and character literals, so you may want a simple '0'
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
i want convert eny caractere in ascii the 0 is a exemple
so if there is some code to calc ascci please send it to me
i need it now
|
|
|
|
|
in .NET an ASCII character is just a character, the first 128 Unicode characters ARE the ASCII characters.
So
'a'
"a"[0]
(char)97
are all the same lower-case a, as they are
a character literal
the way to get the first character of a string
a number cast to a character
If you don't understand the fundamentals, go buy a book and study it. If you have an overall problem, tell us about the problem rather than asking a detail question on what probably isn't even the right detail.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
There is no equivalent; C# developers are smart enought not to write anything as silly as that.
|
|
|
|
|
thank you it's like that when sharing information has a beginning researcher in c #
thank you very much
|
|
|
|
|
Sure, however you should allow some slack for VB coders trying to spit out some C#.
How about
char ascee='0';
char uniquode=Encoding.UTF8.GetChars(Encoding.ASCII.GetBytes(new char[]{ascee}))[0];
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
the out result is the same of first value of ascee no chage ???
|
|
|
|
|
Luc Pattyn wrote: allow some slack for VB coders
They made their sty they can wallow in it.
|
|
|
|
|
sig material it is.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Hi everybody. ...It's been way too long since I've had to issue a production release, but guess what I get to do this week lol
..at any rate, I'm writing up the installme.doc checklist for Production Management to be able to roll our code out to production, and I ran into something that I'm curious to know everyone's thoughts on:
1)Are there any tangible benefits to issuing a true "Release" build to production?
2)Or does it suffice to merely build in "Debug" and not copy over the pdb file that is generated with it?
3)Are they equivalent processes and issuing a "Release" build is merely more explicit in stating "This is built for a production release?"
(Our current SOP is #2)
Thoughts, opinions (other than a mere msdn reference...I'm requesting information from real world experience with the two methods)
"I need build Skynet. Plz send code"
|
|
|
|
|
That depends on your configuration -- usually a release build will use optimizations and the debug doesn't,
and the debug build will include debug symbols and the release doesn't,
so the release version may be quicker and/or more efficient than the debug version.
But you can configure things in other ways if you want.
I have no idea what PDB files do, I wish the compiler wouldn't create them at all, I just delete them and I have no trouble.
|
|
|
|
|
PIEBALDconsult wrote: I have no idea what PDB files do
Its the debugging symbols, its what allows you to break into the code and step through it.
Smart development teams stash away the pdb's from a production release to enable them to debug problems with a specific build of the code at a future date.
|
|
|
|
|
I'm not convinced; I can debug without a PDB file. I believe the debug symbols get built into the EXE.
|
|
|
|
|
You may be able to debug, but you won't get any line numbers without the PDB.
|
|
|
|
|
Then how does the debugger highlight the appropriate line?
|
|
|
|