|
pauli wrote: What type is theHands? I assume Collection is a type?
Collection theHands; // why not = new Collection(); ?
Collection is a generic type. This means that when you create a collection object you have to also provide a type parameter. The collection will then contain objects of the type you specified when you created it. So for a collection of ints you would define it like this:
Collection<int> myintcollection = new Collection<int>();
Don't forget to include a using statement at the top of the file to link to the namespace
using System.Collections.ObjectModel;
Google around for a tutorial on generics to help you understand this. There's loads out there.
pauli wrote: How do I refer to each hand?
Just like you would with an array.
theHands[1];
Or using a foreach loop.
<br />
foreach(PlayerHand hand in theHands)<br />
{<br />
{<br />
pauli wrote: How do I assign a value to theHands?
Once you've created the new collection like this
Collection<PlayerHand> theHands = new Collection<PlayerHand>()
you can call the Add(...) method to add new hands to the collection.
PlayerHand hand1 = new PlayerHand();<br />
theHands.Add(hand1);<br />
pauli wrote:
aHand[i].Cards(j).set =CardArray[4 * j + i];
the above does not work - the error is Cards is a property and i am trying to use it as a method
You're doing exactly what it says. Cards is a property of the hand object. By using round brackets your trying to call a method called Cards (which doesn't exist).
The Cards property is giving you access to a collection object containing all the cards in the hand, which you then want to access with a indexer (square brackets) to get the specific card you want to look at.
If you want to add a card to the collection use the .Add method.
aHand[i].Cards.Add(put the card you want to add here);
pauli wrote: otherwise, I'm back to VB6, forever !
Noooooooooo........
Simon
|
|
|
|
|
Hi,
There appears to be duplicates in my generic collection.
How do I delete the extra ones from inside the generic collection please?
Is there a distinct or group by in generic collection?
Thanks
|
|
|
|
|
Hi,
some facts:
most collections allow duplicate entries; Hashtable/Dictonaries typically do not.
the easiest way to avoid duplicates is to check for them when adding.
the easiest way to remove duplicates is to sort, then scan once for "same as previous".
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Hi all,
I am writing a program that needs to take a login name and password, and then try to authenticate against an AD server. Sounds simple enough so far...
The name and password may be entered by a user (real human being), however it also may be generated by another application (actually, a hardware device that my application is communicating with) that I have no real control over. This other application always generates the "account name" for Active Directory users (so, if the user is First Name = "Ben", Last Name = "de Waal", Display Name = "Ben de Waal", but login name = "bdw123", then the value that is passed is "bdw123").
Using DirectoryEntry("LDAP://" + adServer, userName, userPass, authType) , it seems the userName should be "Ben de Waal" (from the above example) to be accepted - if I try "bdw123", it fails to authenticate. I was considering simply iterating through the user list and then getting the "Ben de Waal" value from the "bdw123" user, however it was pointed out to me (quite rightly) that you could have two users named "Ben de Waal", but with different account names. This would mean that the login attempt may then try the incorrect one, which would be very bad.
Can anyone point me in the right direction for checking the "account name"/password against AD rather than the "user name"/password?
|
|
|
|
|
Hi
I have a resource leak in the very simple project.
Project contains Form with one TextBox control in multiline mode.
After start this app I open Task Manager and see "Handles" count incremental on every 1 second.
The source code is following:
<code>
public partial class Form1 : Form
{
System.Threading.Timer tm;
public Form1()
{
InitializeComponent();
// start timer 1 second interval ...
tm = new System.Threading.Timer(OnTimer, null, 0, 1000);
}
void OnTimer(Object state)
{
// add text in thread safe mode ...
AddTerminalText(" Resource Leak!!! ");
}
delegate void AddTextCallback(string text);
AddTextCallback d;
object[] arg = new object[1];
private void AddTerminalText(string text)
{
if (textBox1.InvokeRequired)
{
if (d == null)
{
d = new AddTextCallback(AddTerminalText);
}
arg[0] = text;
textBox1.Invoke(d, arg);
}
else
{
textBox1.AppendText(text); // add text into control ...
}
}
}
</code>
I don't understand what's wrong
Please help anybody !!!
Roman
|
|
|
|
|
Hi,
I don't see anything wrong but have two comments:
1.
you could try the same with an empty OnTimer() and look for a difference in TaskManager.
2.
if that is the only thing the timer is supposed to do, you'd better use a Forms.Timer
which ticks on the GUI thread, hence no Invoke stuff required at all...
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Hi
Yes of course.
The empty OnTimer handler removes resource leak.
The using Timer from Forms namespace removes leak too.
You are absolutely right.
But problem is that I need to add string into text control from other (not main window) thread
This simple project is created specially for demonstrate a standard method for
add a text string into TextBox control from other thread!
This demo is based on standard sample from MSDN and it has leak!!!
I know that the permanent resource leak is in following part of source code:
delegate void AddTextCallback(string text);
AddTextCallback d;
object[] arg = new object[1];
private void AddTerminalText(string text)
{
if (textBox1.InvokeRequired)
{
if (d == null)
{
d = new AddTextCallback(AddTerminalText);
}
arg[0] = text;
textBox1.Invoke(d, arg);
}
else
{
textBox1.AppendText(text); // add text into control ...
}
}
How I can add text correctly into text box from other thread ?
Roman
|
|
|
|
|
Hi Roman,
your code seems to be correct.
you are not dealing with handles yourself, the only thing you do is create some
objects; they will live their life, and end up being garbage collected. Nothing to
worry about.
you could try running it (with a faster timer, or a for loop somewhere) upto
millions of text lines; you will notice though that it slows down because a textbox
needs to concatenate text to do AppendText (a listbox would not really slow down
since it does not concatenate its items).
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Hi Luc
I will try to test more ... Maybe GC wil wake up and will do its job ....
The problem that I see leak after remove AppenText() method at all:
private void AddTerminalText(string text)
{
if (textBox1.InvokeRequired)
{
// it seems like leak somewhere here ..........
if (d == null)
{
d = new AddTextCallback(AddTerminalText);
}
arg[0] = text;
textBox1.Invoke(d, arg);
}
else
{
//Don not change Text of control !!!!!! Line is commented out !!!!! Do nothing!!!!
//textBox1.AppendText(text); // add text into control ...
}
}
Anyway all this does not look good ...
Roman
|
|
|
|
|
Hi Roman,
as I told you before, AppendText appends new text to existing text, so it has to
allocate a new string and copy both parts in there, generating at least one object;
and a growing one, the more appends you do. So the GC is bound to kick in sooner
or later. If you find it hard to believe I suggest you try with a ListBox instead.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Hi Luc
I undestand that AppendText do something with memory or other objects ...
And GC can work later.
Please note that my lalest source code does not call TextBox.AppendText(..)
and does not change Text property of control at all. But Handles are leaking!
It seems like leak is not related with Text property or with AppendText() method of TextBox class.
Problem with cross threading call.
It's very strange.
Anyway thank you very much!
Roman
|
|
|
|
|
Interesting!
I can't get it to work at all with AppendText . If I use
textBox1.Text += text;
then the handles count up to 155 then reset down to 145 and repeat. Presumably they're being mopped up on garbage collections, so they don't really leak.
Weird.
Regards,
Rob Philpott.
|
|
|
|
|
Hi Rob
You are right. It's very interesting.
I see leak even when I don't change Text in the control.
Please see my more detail reply to Luc above.
Roman
|
|
|
|
|
I have done more tests.
It seems like Handles counter grow up from 150 up to 2500 value.
After 2500 it resets back to 200 handles and increases again to 2500 and so on.
It is stupid behavior. Why "textBox1.Invoke(d, arg);" call takes system resourse (Handle).
Roman
|
|
|
|
|
Hi Folks,
I would like to make an application to access a network camera(separate IP, AXIS communication device) using C#. I just need to play the video on my desktop and not saving or anything.
I am new towards (High Level or dialog based)windows software development, so please help me and would be nice with some sample code examples.
BR,
Sher
|
|
|
|
|
Hi,
two suggestions:
1.
when new to a combination of issues, get acqainted to each of them individually.
So start creating a very simple app, then add the things you will need one by one.
2.
Look around either here at CodeProject or ask Google.
These are some camera related articles[^].
Hope this helps.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
I want to take snap shot of Current application which is running on other machine.
Uptill now I successfully done to take printpreview of the current application form on local machine.
I want to take snap shot of the current screen.
How Can I go further?
|
|
|
|
|
Hello!
You need to create the small client application that caputures the
current desktop using GetWindowDC and GetWindow API.You can save these
bytes or send it to your sever application using SendMessage or by using
the sockets.
ritz1234
|
|
|
|
|
But How Can I get the Snap Shot of the Current Application running on a local machine using windows application.
Because I dont have idea about that.
Regards,
sjs4u
|
|
|
|
|
He just told you. If you can't understand what he said, then you probably can't get what you're looking for.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Please do not post your question more than one time.
Click[^]
Kristian Sixhoej
"Failure is not an option" - Gene Kranz
|
|
|
|
|
I am using VS 2003 to debug an web application.
It works well sometimes, but sometimes it does not. The status bar shows "Setting up server for debugging". It just keeps setting it up forever. I have also put localhost in the trusted sites but no help.
what can be the reason??
|
|
|
|
|
Well, it could be that VS2003 is as flakey as hell when debugging web projects on IIS. This happens to me all the time and I've just got used to either firing IISRESET from the command prompt or killing the ASP.NET worker process from task manager.
Regards,
Rob Philpott.
|
|
|
|
|
Well, I am new to this. Does this mean that have no ti live with this and that I just cannot do anything about it?
|
|
|
|
|
If its the same problem I have then you may have to get used to it. I think its something to do with shadowing in IIS which is a feature where you can deploy stuff to IIS without a break in service. Maybe you can switch it off - I haven't looked. First off, determine whether doing IISRESET after a build stops this problem or whether its something else.
Regards,
Rob Philpott.
|
|
|
|