|
From the docs.
Note If the calculated value of a counter depends on two counter reads, the first read returns 0.0.
My guess is that the uptime counter requires two reads
James
Sonork ID: 100.11138 - Hasaki
"Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. " - Michael P Butler Jan. 18, 2002
|
|
|
|
|
Yes, I have read that note, but it does not make any sense. Why should I have to read a counter twice to get the system up time??
A related question: I am trying to write the same program in managed C++ but the System::Diagnostics namespace does not contain the PerformanceCounter class. Why? Shouldn't the class library be identical beetween the languages?
thanks for the help
/Mike
|
|
|
|
|
I found the solution to my managed C++ problem. I had to add a
#using <System.dll>
to the program. Stupid newbie mistake...
|
|
|
|
|
Hello. I am building a custom web control, and I need to render child controls which are passed as literal strings. I am using ParseControl for this. However, it doesn't seem to be working. When I compile my custom control I get "CS0118 System.Web.UI.TemplateControl.ParseControl denotes a method where a class was expected". My code looks like: this.Controls.Add(new LiteralControl(new System.Web.UI.TemplateControl.ParseControl("<asp:textbox id=\"txt\" Text=\"Person\" runat=\"server\"/>"))); I tried just ParseControl as apposed to System.Web.UI.TemplateControl.ParseControl but when I used ParseControl I got the error "No class or namespace named ParseControl in MyControl, (are you missing an assembly reference?)" But I have System.Web.UI imported into my class. I don't know what to do. Any help is very greatly appreciated.
|
|
|
|
|
ParseControl is a method of TemplateControl which is an abstract class that Page inherits from. You use ParseControl when you want to add a new ASP.NET server control to the page.
void Page_Load(object sender, System.EventArgs e)
{
Button myButton = (Button)ParseControl("<asp:button runat = \"server\"/>");
myButton.Text = "Hello World!";
Controls.Add(myButton);
}
A literal control is used when you wish to insert HTML into your page, not ASP.NET server controls.
If you want to put HTML in your website, use Controls.Add(new LiteralControl(myHTML));
If you want to add a new server control (all server controls have runat="server" in the HTML for them) use the first code example.
HTH,
James
Sonork ID: 100.11138 - Hasaki
"Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. " - Michael P Butler Jan. 18, 2002
|
|
|
|
|
Thanks alot, but that's not really what I was trying to do.
You see, I'm getting this string for the ASP.NET web controls from a DB. They are dynamic. I don't know wether they will be buttons, labels, dropdownlists, or what.
I am trying to use ParseControl on that literal string. The literal string is the actual code of the ASP.NET web controls, not references to instantiate them or set their properties.
Does that make sense now? I have to find out how to use ParseControl in that sort of instance.
Thanks alot.
|
|
|
|
|
ok, i think i see what you're doing.
In the Page_Load event
Controls.Add(ParseControl(stringFromDB));
You'll have to set all your properties for the control in the string coming from the DB ie <asp:button id="button1" text="push me">
In general you use LiteralControl for static HTML, use ParseControl when you are creating a server control.
HTH,
James
Sonork ID: 100.11138 - Hasaki
"Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. " - Michael P Butler Jan. 18, 2002
|
|
|
|
|
I'm using the code you provided above, but it still does not work. I'm not doing this in an ASPX page. I am calling ParseControl in a custom web control source (.CS file), that's being compiled into an assembly. And when I compile the assembly, I get the error:
"ParseControl does not exist in the class MyControl"
so I reference it explicitly:
Controls.Add(System.Web.UI.TemplateControl.ParseControl(stringFromDB);
When i compile the assembly I get:
"CS0120: An object reference is required for the nonstatic field, method, or property 'System.Web.UI.TemplateControl.ParseControl(string)'"
I've got to find out how to solve that.
Thank you for all your help.
|
|
|
|
|
ok, now we're getting somewhere
There are only two classes that inherit from TemplateControl, Page and UserControl. So your control is going to have to inherit from one of these (most likely UserControl) to make use of the ParseControl method.
Because ParseControl is not a static method you need an instance of TemplateControl (or a derivative of it) to call it. But TemplateControl is an abstract class so you cannot create an instance of it, leaving you with having to have an instance of one of TemplateControl's derivatives. Out of the box your choices are Page and UserControl.
Is it possible to change your control so it inherits from UserControl instead of Control?
I'll admit I'm no where near up-to-date on ASP.NET as I am C# and the rest of the framework, so I'm just throwing out ideas
James
Sonork ID: 100.11138 - Hasaki
"Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. " - Michael P Butler Jan. 18, 2002
|
|
|
|
|
Thanks for all the help!! ParseControl now works perfectly
|
|
|
|
|
Sorry one more question on jag arrays
how would i get the .Length of each dimension if they vary on the ammount of 'columns'
thanks heaps
|
|
|
|
|
Assuming test is your array and the data stored in the particular row you want is a string.
((string[]) test[myrow]).Length;
HTH,
James
Sonork ID: 100.11138 - Hasaki
"Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. " - Michael P Butler Jan. 18, 2002
|
|
|
|
|
Hi,
is it possible to have a jaggard array of different datatypes on each row ?
|
|
|
|
|
I don't think so.. because you're declaring an array that holds arrays of a certian type. I think you're going to want an object or a struct. I'm guessing a stuct is going to be more suited to what you need.
Example..
using System;
class MyApp
{
static void Main() {
myStruct testVar = new myStruct();
testVar.intArray = new int[] {1,2,3};
testVar.strArray = new String[] {"One", "Two", "Three"};
Console.WriteLine("{0} - {1}", testVar.intArray[2], testVar.strArray[2]);
}
struct myStruct
{
public int[] intArray;
public string[] strArray;
};
}
structs are going to be faster than objects. But if you want to iterate through members, you should create an object that can be used with a "foreach" loop.
|
|
|
|
|
It is possible, there is on cavet though. If one of your datatypes is a ValueType (ie, you can't set it to null) an exception will be thrown when you do a foreach on the array.
object [] test = new object[2];
test[0] = new string[4];
test[1] = new Type[2];
int j;
for(j = 0; j < 4; j++)
{
((string[]) test[0])[j] = "moo" + j.ToString();
}
((Type[]) test[1])[0] = typeof(object);
((Type[]) test[1])[1] = typeof(System.Guid);
foreach(object [] t in test)
{
foreach( object i in t )
{
Console.Write("{0}, ", i);
}
Console.WriteLine("");
}
Console.ReadLine();
Sorry for the horrible formatting, the pre tag seems to be taking out all blank lines
James
Sonork ID: 100.11138 - Hasaki
"Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. " - Michael P Butler Jan. 18, 2002
|
|
|
|
|
Didn't even think about an object type.. thanks for pointing that out.
|
|
|
|
|
Thanks a bunch guys
|
|
|
|
|
I've been playing around with C# and I like it for some projects. What I've been playing around with lately is socket programming. It's simple enough to make a tcp or udp client/server environment. What I was thinking I'd try next is to emulate the "netstat" command. I'm just not sure how to go about capturing what's listening where. Any tutorials or hints on this?
|
|
|
|
|
I don't think there is a pure .NET way to do this. You'll have to use p/invoke and call into some system dlls (winsock2?) to get the information.
I don't have any experience with winsock to know where to look though.
James
Sonork ID: 100.11138 - Hasaki
"Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. " - Michael P Butler Jan. 18, 2002
|
|
|
|
|
How can I remove the title bar completely from a Windows forms application?
|
|
|
|
|
myform.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
This works on a form with default settings.
James
Sonork ID: 100.11138 - Hasaki
"Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. " - Michael P Butler Jan. 18, 2002
|
|
|
|
|
After installing the final verison of VS.NET, all the c# applicatins give an error and don't work and even compile. anyone ca help me?
|
|
|
|
|
none of your existing applications will work as they rely on earlier versions of the .NET runtime, but you should be able to at least compile them.
The only hitch I can think of off the top of my head is any .resx's having an older format (and version number).
Here's a link to the .NET team's upgrade page.
If you have any more problems please post more specific examples (compiler errors etc)
HTH,
James
Sonork ID: 100.11138 - Hasaki
"Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. " - Michael P Butler Jan. 18, 2002
|
|
|
|
|
Hi James
Thanks a lot
It worked after using the tool to convert the .resx files
|
|
|
|
|
I wrote a windows service in c#, with the final version of .NET. I am able to start the service in just a fraction of a second. But when I copy the same service exe to a different machine (which also has the .NET final version) and try to start the service, it times out throwing Error 1053:. What could be the reason?
omkamal
|
|
|
|