|
that is why I suggested you run a little test, such as:
public void Runner(object dummy) {
string text=dummy as string;
for(;;) {
for(int i=0; i<1000000000; i++) {}
Console.WriteLine(text);
}
}
Create a Console App, have it create N background threads executing Runner, each with a different text argument, and watch Task Manager
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).
|
|
|
|
|
Your explanations sounds like STA is a per-project setting. It's not. It's actually a per-thread setting, and the attribute on void Main just controls the setting for the main thread.
You can have both STA threads and MTA threads in the same application. And yes, you can have multiple STAs running concurrently.
COM objects living in a STA have all their calls executed on the thread associated with that STA (calls are marshaled to that thread and executed sequentially).
COM objects living in a MTA have their calls executed by any MTA thread, so there can be many calls running concurrently.
Of course, all this is revelant only for threads that create COM objects. Some Windows Forms controls require the GUI thread to be in a STA, but apart from that, threading apartement doesn't matter for a pure .NET application.
|
|
|
|
|
Thanks for clarifying that. I have known this, but it faded away a bit, and that fact confirms your final statement, it not being very relevant for a pure .NET application, which is what I do most of the time.
I do recall threads could choose their STA/MTA inclination, but only once. What isn't clear to me (I should look it up actually) is the consequences of the STA/MTA choice made on static Main(); does that only affect the main thread, or does it set the default for all threads?
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).
|
|
|
|
|
Mr. Pattyn,
My experience thus far has been that the main method only sets the initial thread's apartment model, not the default for future threads.
In Christ,
Aaron Laws
http://ProCure.com
|
|
|
|
|
Dear Mr. Grunwald,
Thanks for the explanation. That's right, I was thinking of it as a program setting, not a thread setting. So, one thing interests me (to hijack my own thread...heh), that is,
``calls are marshaled to that thread..."
This confuses me. So, perhaps a thread coming into COM looking to get something done (open a OpenFile Dialog or something) comes in, COM looks at him and decides he's STA. So, does COM hijack that thread or create a new thread? How can COM marshal calls on a thread that it doesn't own? Or, is this always done in a message pump? Perhaps you could point me to an article on this.
Your answer is excellent, rating 5. Thanks.
In Christ,
Aaron Laws
http://ProCure.com
|
|
|
|
|
Welcome everyone
Have a big problem in the end this code
This code works with one of the chat games networks
But it does not appear the Arabic letters
But appear in this form
????????????
While the characters appear as English is
How can I deal with this situation
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Threading;
using System.Text;
using System.IO;
namespace ConquerSx.PacketHandling
{
public class Chat
{
public static void Handle(Main.GameClient GC, byte[] Data)
{
MemoryStream MS = new MemoryStream(Data);
BinaryReader BR = new BinaryReader(MS);
BR.ReadBytes(8);
ushort ChatType = (ushort)BR.ReadUInt32();
BR.ReadBytes(13);
string From = Encoding.ASCII.GetString(BR.ReadBytes(BR.ReadByte()));
string To = Encoding.ASCII.GetString(BR.ReadBytes(BR.ReadByte()));
BR.ReadByte();
string Message = Encoding.ASCII.GetString(BR.ReadBytes(BR.ReadByte()));
BR.Close();
MS.Close();
#region BadWords
Message = Message.Replace("http:/", "****");
Message = Message.Replace(".net", "****");
Message = Message.Replace(".com", "****");
Message = Message.Replace(".tk", "****");
Message = Message.Replace("www", "****");
Message = Message.Replace("damn", "****");
Message = Message.Replace("f***", "****");
Message = Message.Replace("sh*t", "****");
Message = Message.Replace("stupid", "******");
Message = Message.Replace("wtf", "***");
Message = Message.Replace("idiot", "*****");
Message = Message.Replace("f***er", "******");
#endregion
modified on Friday, June 11, 2010 9:26 PM
|
|
|
|
|
There is far too much code posted here and it is not properly formatted to be readable. Please read How-to-get-an-answer-to-your-question[^], then go back and edit your question to format your code properly and also remove all the sections not relevant to your question.
It's time for a new signature.
|
|
|
|
|
I seriously doubt that anyone has got the time to wade through all of that code. Might I suggest that you cut it down to only display the important parts. Anyone that is curious enough may ask for more. In any case your question is not clear: try to rephrase it.
me, me, me
"The dinosaurs became extinct because they didn't have a space program. And if we become extinct because we don't have a space program, it'll serve us right!"
Larry Niven
nils illegitimus carborundum
|
|
|
|
|
Please do not post whole code and read
this[^] post before you ask any question.
Put your code in proper format using code block
functionality of code project.
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
Hi,
welcome to CodeProject. We are here to help you. However we also insist on you making that no harder than necessary, so you'd better read the forum guidelines first. There is a nice "how to ask a question" or "how to get an answer" message.
It will tell you many things, such as choosing an informative subject line, including only relevant parts of code, and using PRE tags when doing so.
I did not read all of your code, it is simply too hard. I did notice:
1.
you have a couple of Encoding.ASCII in there, that is one way of turning foreign characters into question marks.
2.
you seem to have a GC class, that isn't the best choice of names, as .NET already has a GC class. There probably isn't a real problem here, it is however a bit confusing.
Hope this helps.
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).
|
|
|
|
|
TL;DR
Btw, this is not a forum with BB code.
|
|
|
|
|
System.TooManyTLAException at line 1
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).
|
|
|
|
|
Some statistics (from OpenOffice.org Writer):
30 pages (A4 using Courier 10pt)
1770 lines excluding blanks
1865 total lines
As others have said far too much for anyone to think about reading.
And I haven't mentioned the lack of formatting.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
The only valid measurement of code quality: WTFs/minute.
|
|
|
|
|
riced wrote: As others have said far too much for anyone to think about reading.
There goes the USP of obfuscation-tools
I are Troll
|
|
|
|
|
riced wrote: And I haven't mentioned the lack of formatting.
Well, you should have.
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).
|
|
|
|
|
You need to use one of the Unicode Encoding classes rather than ASCII.
|
|
|
|
|
Hi all,
I am using combobox Selected Change committed event,
and want the text selected by selected by user.
But problem is it only gives me text which was previously selected.
Suppose there are items as A, B, C, D
Now if user selects A on cmbTables_SelectionChangeCommitted event
its giving blank,
if again user selects A then its giving A.
Its giving the value which was previously selected.
private void cmbTables_SelectionChangeCommitted(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine(cmbTables.Text);
}
Why this?
Is there way to overcome this?
Also if some items are present, it show blank, user have to select 1st item from dropdown.
I know we can set that thru coding, but why can't it set by default to 1st item.
regards,
|
|
|
|
|
try
cmbTables.SelectedText or
cmbTables.SelectedItem depending on how you filled the combobox, instead of
cmbTables.Text
|
|
|
|
|
None of them help,
All are giving me previously selected item text
|
|
|
|
|
I've never used the SelectionChangeCommitted event; did you notice it is part of Microsoft.VisualBasic.Compatibility.VB6 which suggests me to avoid it, it probably exists to mimic some quirks from VB6. I have used SelectedIndexChanged successfully, however I also code carefully with all such XYZChanged events, as some of them will fire more than once (changing a selection may be an unselect followed by a select), and Changed sometimes is and sometimes isn't to be taken literally, i.e. they may also fire when the same selection is made again.
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).
|
|
|
|
|
Luc Pattyn wrote: did you notice it is part of Microsoft.VisualBasic.Compatibility.VB6
How did you notice this?
If I look into the object browser i just see:
Public Event SelectionChangeCommitted(ByVal sender As Object, ByVal e As System.EventArgs)
Member of System.Windows.Forms.ComboBox
But in the Microsoft.VisualBasic.Compatibility.VB6 namespace there is :
Public Event SelectionChangeCommitted(ByVal sender As Object, ByVal e As System.EventArgs)
Member of Microsoft.VisualBasic.Compatibility.VB6.ComboBoxArray
|
|
|
|
|
I'll let you in on a little secret: I occasionally read the documentation; Google the keyword (class name or more) to locate the relevant MSDN page, and pay attention to one of the first lines, which names the namespace. If it contains VisualBasic or VB6, I always suspect it is there for compatibility, probably to copy historic quirks.
Intellisense is great for saving you from some typing, and for suggesting member names, it is not a replacement for the documentation though. When I start using a new class, I read the class page and the list of members; and for each new class member I use, I would read the specific page, especially looking at the remarks, and the list of exceptions, as they often contain hints on less-than-obvious behavior that is to be expected.
In this particular case, I may have been too hasty though, seems like SelectionChangeCommitted also is a normal event in System.Windows.Forms.ComboBox, so I must have read the wrong page. However, I stand by my comments on XyzChanged events in general.
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).
|
|
|
|
|
When i use SelectedText, its give previously name.
But if i use SelectedIndex, its giving currently selected item.
I am trying to achieve. There is a DataGridView. I am filling DataSet with approx 20 tables. Then adding these Datatable names to combobox.
Now when user selects a Datatable from comboxbox, lsetting dataMember property of DataGridView to Table Name.
Ques -> Is this Approach correct?
Here i also have to declare DataSet at class level (which i think remain in memory until class/application alive).
void SomeMethod()
{
dsTemp = new DataSet();
dsTemp.ReadXml(ofdXmlFile.FileName);
dgvDS.DataSource = dsTemp;
for (int i = 0; i < dsTemp.Tables.Count; i++)
{
txtContent.Text += dsTemp.Tables[i].TableName + "\r\n";
cmbTables.Items.Add(dsTemp.Tables[i].TableName);
}
}
DataSet dsTemp = null;
private void cmbTables_SelectedIndexChanged(object sender, EventArgs e)
{
dgvDS.Columns.Clear();
dgvDS.DataMember = dsTemp.Tables[cmbTables.SelectedIndex].TableName;
}
Now above working correctly.
But when i use this below one its not working as expected
But here i dont have to declare DataSet at class level(and it also got garbage collected once SomeMethod Exit).
void SomeMethod()
{
DataSet dsTemp = new DataSet();
dsTemp.ReadXml(ofdXmlFile.FileName);
dgvDS.DataSource = dsTemp;
for (int i = 0; i < dsTemp.Tables.Count; i++)
{
txtContent.Text += dsTemp.Tables[i].TableName + "\r\n";
cmbTables.Items.Add(dsTemp.Tables[i].TableName);
}
}
private void cmbTables_SelectedIndexChanged(object sender, EventArgs e)
{
dgvDS.Columns.Clear();
dgvDS.DataMember = cmbTables.SelectedText;
}
Also one more quest, when i try to iterate dataset thru foreach loop like
foreach (DataTable dt in dsTemp)
{ txtContent.Text += dt.TableName + "\r\n";
cmbTables.Items.Add(dsTemp.Tables[i].TableName);
} it gives error why?
Error 1 foreach statement cannot operate on variables of type 'System.Data.DataSet' because 'System.Data.DataSet' does not contain a public definition for 'GetEnumerator'
How to overcome this? if i want to use foreach only?
|
|
|
|
|
1.
The hint is in the documentation:
"SelectedText gets or sets the text that is selected in the editable portion of a ComboBox".
A ComboBox allows you to choose one item from a list; doing so will fire some events and set some properties, in particular SelectedIndex and SelectedValue. These apply to you point-and-clicking in the list.
It also often allows you to type a text yourself; if so, you can edit the text, select part of it, copy, cut, paste, etc. There SelectedText works like it does in a TextBox. That is unrelated to point-and-clicking in the list.
When you do point and click, the TextBox part will reflect what you have selected, and under some conditions, it will also select it (turning it white on blue), at that time SelectedText would become equal to SelectedValue.
Hence: use SelectedIndex for retrieving the index inside a SelectedIndexChanged handler.
2.
Hum Dum wrote: foreach (DataTable dt in dsTemp)
does not work when dsTemp is a DataSet. A DataSet holds tables but does not enumerate them automatically.
However
foreach (DataTable dt in dsTemp.Tables)
should work for you.
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).
modified on Friday, June 11, 2010 8:51 AM
|
|
|
|
|
Thanks for your reply and time.
also could you give some light on DataSet object i declared. Given the 2 approaches i used, Is my concern is correct i.e
a) By declaring DataSet at form level(outside method). Is this going to remain alive until form object is alive?
Am i correct here?
regards
|
|
|
|
|