|
I have been reading alot about C# determinism, and most of the literature addresses destructors. I understand that the garbage collection is now responsible for calling the class destructor, and the GC is undeterministic. I have read recommendations to implement IDispose and have the client call Dispose(), but what about client server architectures. If I have one C# server connected to multiple clients, which client calls Dispose()? Isn't this why reference counting was invented?
My biggest concern is whether or not my C# server will contain a message pump - someone alluded earlier that it will. Anyone who has created a COM STA server will know that message pumps make your code slow and VERY undeterministic. How to you create a message pump free C# server (something equivilent to a MTA server in COM)?
Thanks,
Aaron
|
|
|
|
|
I created a Windows Application project in C#.
I created a number of forms that are inherited forms.
If I keep the original form in the project, I can only set that form as the Startup object, and it goes without saying that if I remove it, I cannot set anything to the Startup object. (compile says myNamespace.formname does not exist if I manually enter the inherited form name)
Why can't I set an inherited form as a Startup object and how do I get around this???? Even if I add a normal form (not inherited) after my inherited forms it does not allow me to set even that normal form now. In fact, I get no dropdown box in the StartObject property of the project!!!!!
_____________________________________________
I have a tendancy to where my mind on my sleeve I have a habit of losing my shirt...
|
|
|
|
|
Never mind. I found my problem....I have to add the following section to my code manually:
<br />
[STAThread]<br />
static void Main() <br />
{<br />
Application.Run(new myForm());<br />
}<br />
_____________________________________________
I have a tendancy to where my mind on my sleeve I have a habit of losing my shirt...
|
|
|
|
|
In a C# hash is it possible to get an item by its key and to get a key by a value? Something like this:
myhash.Add("David","C#")
myhash.Add("Chris","Perl")
?myhash.Items("David") -- should be C#
?myhash.Keys("Perl") -- should be Chris
What is the correct syntax?
sigh, the things you do for date/times.
*->>Always working on my game, teach me
*->>something new.
cout << "dav1d\n";
|
|
|
|
|
Add a key value pair:
myhas["David"] = "C#";
Get a key by it's value:
string item1 = myhash["David"]
Iterate through all items:
foreach( string key in myhash.Keys )
{
string item1 = myhash[key];
}
Determine if hashtable contains a particular key:
if( myhash.Contains("David") )
{
}
Determine if hashtable contains a particular value:
if( myhash.ContainsValue("C#") )
{
}
In general you won't want to look up a key by it's value since keys are (usually) unique, but values aren't. Does this help?
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
Thanks Matt -
I needed to have a hashtable of months of the year:
"January","1"
"February","2"
...
and be able to get a month based on a numeric index OR an index based on a month string.
I thought it would be easy with a Hashtable but you're right - it doesn't support lookups by value assuming you could have multiple 'values' with different keys. But there are a lot of cases like this where I know there is a one to one mapping of name/value pairs. Items that are always used in association and are unique.
I used a simple array and wrote a finder method that looked like this:
<br />
string[] months = {"Jan","Feb","Mar",...}<br />
<br />
private int GetMonthIndex(string mo){<br />
for(int i=0;i<mos.Length;i++){<br />
if(mos[i]==mo)return i+1;<br />
}<br />
return -1;
}<br />
Incidentally I asked my perl jedi master and he must have been laughing when he wrote this:
<br />
$hash{'David'} = 'C#';<br />
$hash{'Chris'} = 'Perl';<br />
@keys = grep { $hash{$_} eq 'Perl' } keys %hash; #perl is s1ck<br />
In the end, while I didn't change my use of a simple array and a brutally slow sequential search, I wrote this for future reference:
<br />
public static string GrepHashForKey(Hashtable ha, string search){<br />
foreach(object o in ha.Keys){<br />
if(ha[o].ToString().Equals(search))<br />
return o.ToString();<br />
}<br />
return "";<br />
}<br />
*->>Always working on my game, teach me
*->>something new.
cout << "dav1d\n";
|
|
|
|
|
Just use an ArrayList. Just make sure you add the months to the ArrayList in the right order. Like this:
ArrayList months = new ArrayList();
months.Add("January");
months.Add("February");
int monthNum = months.IndexOf("January") + 1;
string monthName = months[monthNum - 1];
That should do it eh?
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
A two liner for my woes! Humbling but good to know -
Thanks Matt.
*->>Always working on my game, teach me
*->>something new.
cout << "dav1d\n";
|
|
|
|
|
afronaut wrote:
I needed to have a hashtable of months of the year:
"January","1"
"February","2"
...
and be able to get a month based on a numeric index OR an index based on a month string.
static string PrintMonth(int i)
{
return new DateTime(0).AddMonths(i).ToString("MMMM");
}
static int PrintMonthNr(string month)
{
for (int i = 0; i < 12; i++)
{
if (PrintMonth(i) == month) return i;
}
return -1;
}
"I dont have a life, I have a program."
|
|
|
|
|
One option (in addition to those you already found) would be TWO hash dictionaries. You could create a class that holds both the key name and value, then have both hashes store the same object, one using the key name as the key and the other using the value as the key.
Additionally, you could create a class that wraps this sort of behaviour, giving you exactly the syntax you wanted.
John
|
|
|
|
|
It appears that the old VB6 approach of a messageBox function that displayed info, possibly got info, and passed back the info or the button selection does not exist in the Framework.
To do a modal dialogBox I need to create my own form and set the AccessibleRole = Dialog.
For my buttons, I set DialogResult to the value I want to return.
So I guess that I would follow the following steps to create a Verify (yes, no) dialog box:
Create a form named Verify.
Set the AccessibleRole to Dialog.
Define my screen (example: Do you want to do this?) with two buttons, Yes, No. Define DialogResult as No for the No button and Yes for the Yes button.
In my main program, I code:
VerifyDialog myDialog = new VerifyDialog;<br />
if (myDialog.ShowDialog(this) == DialogResult.Yes)<br />
{<br />
go ahead and do this.<br />
}
Am I on the money or about to toss a handgrenade?
Thanks for help.
_____________________________________________
I have a tendancy to where my mind on my sleeve I have a habit of losing my shirt...
|
|
|
|
|
try this instead :
VerifyDialog myDialog = new VerifyDialog;
if (myDialog.Show()==DialogResult.Yes)
{
go ahead and do this.
}
Cheers,
Daaron
|
|
|
|
|
You were responding as I was updating my post as I was also doing the coding as I was following the message board. Is that multi-tasking or what???
_____________________________________________
I have a tendancy to where my mind on my sleeve I have a habit of losing my shirt...
|
|
|
|
|
The AccessibleRole property is a red herring - it's related to Accessibility for disabled users.
|
|
|
|
|
If you are just asking for confirmation you can use the MessageBox class to display a message box (MsgBox in VB6).
If you need the user to input something (something beyond clicking a button) then you'll have to use the approach you have now.
[edit]
Sample code would probably help you
MessageBox.Show("Are you sure you want to do this?",
"Are you sure?",
MessageBoxButtons.YesNo
);
The Show method returns a DialogResult like you are already using.
[/edit]
James
- out of order -
|
|
|
|
|
I am using transparency effects to create shaped windows, I have followed the basic tutorial found here :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchShapedWindowsFormsControlsInVisualStudioNET.asp
Now on my machine this works like a dream, but on other machines it does not work correctly - transparency doesnt work at all. All machines are set to the same resolution and colour depth (32bpp).
Does anybody have any ideas on the cause of this?
More info :
The image in question is a 24bit bmp, the transparency key I am using is 255,0,255 (fuschia)
|
|
|
|
|
MrEyes wrote:
Now on my machine this works like a dream, but on other machines it does not work correctly - transparency doesnt work at all. All machines are set to the same resolution and colour depth (32bpp).
Are the other test machines running Windows XP?
As far as I know only WXP supports transparency out of the box.
Paul Watson Bluegrass Cape Town, South Africa Ray Cassick wrote: Well I am not female, not gay and I am not Paul Watson
|
|
|
|
|
Windows 2000 and greater support transparency. (95/98/Me Dont)
Contract Software Developer: andrew_lewis@mail.com
|
|
|
|
|
Andrew Lewis wrote:
Windows 2000 and greater support transparency. (95/98/Me Dont)
Ahhh, thanks, my mistake
Paul Watson Bluegrass Cape Town, South Africa Ray Cassick wrote: Well I am not female, not gay and I am not Paul Watson
|
|
|
|
|
Subject.
=====================
http://wasp.elcat.kg
|
|
|
|
|
Ahhh, thanks, my mistake
Paul Watson Bluegrass Cape Town, South Africa Ray Cassick wrote: Well I am not female, not gay and I am not Paul Watson
|
|
|
|
|
Thanks for the replies but unfortunatly they dont bring me any closer to an answer. The following is a summary of the test machines :
1) Win 2000 (SP2) - 1024*768 - 32bit color depth
2) Win XP - 1024*768 - 32bit color depth
3) Win 2000 (SP2) - 1024*768 - 32bit color depth
4) Win XP - 1024*768 - 32bit color depth
Now my form background transparency works fine on machines 1 & 2 but does not work on other two (2 & 3). I have also noticed that "opacity" works on all machines (i.e. setting the entire form to 25% opactity results in a "see through" form)
I have also tried using different image formats (i.e. gif) and also different transparency colors (current using fuschia (255,0,255) all to no avail.
I am 100% this is probably all being caused by some option I have missed, but if that is the case it isnt detailed in MSDN link above
Once again, thanks for the replies so far, any further suggestions would be greatly appreciated
PS. if anybody is interested enough, a copy of the VS .NET projects files can be found here (http://www.randomportal.com/shapedwindow.zip 256kb) - bear in mind this is a test application and is not "pretty"
PPS. Alternativly the following is the source code for the form (bear in mind that the image is held with a resx resource file). This code is also autogenerated by VS .NET, so one would assume that its correct, hmmmm
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace ShapedWindow
{
public class Form1 : System.Windows.Forms.Form {
private System.ComponentModel.Container components = null;
public Form1() {
InitializeComponent();
}
protected override void Dispose( bool disposing ) {
if( disposing ) {
if (components != null) {
components.Dispose();
}
}
base.Dispose( disposing );
}
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackgroundImage = ((System.Drawing.Bitmap)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(229, 228);
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Form1";
this.TopMost = true;
this.TransparencyKey = System.Drawing.Color.Fuchsia;
}
[STAThread]
static void Main() {
Application.Run(new Form1());
}
}
}
|
|
|
|
|
MrEyes wrote:
I have also noticed that "opacity" works on all machines
Silly me, I thought you were talking about opacity all along.
Anyway I had a look around and from what I can tell shape forms using the TransparencyKey are not reliable.
Shaped Windows Forms and Controls in Visual Studio .NET[^] says "Note Monitors set to a color depth of greater than 24-bit can display problems with certain parts of the form not being transparent, despite setting of the TransparencyKey property. To avoid this problem, ensure that the monitor's color depth is set to less than 24-bit in the Display control panel. When developing applications that feature this transparency, keep in mind that you will have to make your users aware of this issue." which is pretty pathetic IMO as they offer no help or even admit there is a bug.
Paul Watson Bluegrass Cape Town, South Africa Ray Cassick wrote: Well I am not female, not gay and I am not Paul Watson
|
|
|
|
|
Buggary
I saw that section and speed read it, assuming it was some inconsequential bug
|
|
|
|
|
Sooooo
Does anybody have any experience of using Transparent BLT in C#?
|
|
|
|