|
He's not going to listen to you. He built a DOS-based masked edit thing that's much better than the one in .Net (his claim, not mine). The absurdity is that if he's got the skillz, why the hell is he in here asking how to do it?
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hi
I am working on a project in which I need to NUnit testing. To do that I need to write tests for each class. I am trying to automate that process.
1. How to know names of public properties of class in .Net dynamically?
2. I am also looking for property types to set some default values.
3. There might be nested classes also. I am wondering how to traverse that nested tree?
Please advice. Thanks
Pankaj
|
|
|
|
|
|
I'm sure if you look around you'll find something that already exists to do this kind of job.
|
|
|
|
|
Using LINQ because it's so much easier...
1) How to know names of public properties of classes in .NET dynamically?
var properties = yourType.GetProperties().Select(p => p.Name); 2) Property types
var properties = yourType.GetProperties().Select(p => p.PropertyType);
var instance = Activator.CreateInstance(properties.First()); 3) Nested classes
var childClasses = typeof(Program).GetNestedTypes().Select(t => t.Name);
Note you can retrieve these without LINQ just forget the .Select(...) pattern, but you asked for names which implies strings so I used LINQ to extract the names rather than a loop.
|
|
|
|
|
Hi Everyone,
I'm running into a major problem with the combobox created by bestcomy. I also posted a comment on that article but its also very urgent so I thought I would try here as well. I recently had to re-install VS studio 2002 on my laptop and the code that I had to run the combobox created by bestcomy is no longer working. I'm getting this error:
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Method LoadPostData in type Bestcomy.Web.UI.WebControls.ComboBox from assembly LoadPostData does not have an implementation.
Source Error:
Line 187: <td class="heading" width=135px>Central Office:</td>
Line 188: <td width=220px>
Line 189: <bestcomy:ComboBox id="ddlCO" runat="server" Width="120px" AutoPostBack="true" ></bestcomy:ComboBox>
Line 190: </td>
Line 191: <td>
Has anyone seen anything like this before? Any help would be greatly appreciated. thanks!
|
|
|
|
|
ceetee,
Wrong forum. You need ASP.NET.
Regards,
Gareth.
|
|
|
|
|
|
Ive searched the web and it seems that blocking Ctrl+Alt+Del is almost impossible in Windows XP. Is there a way to keep your program constantly looking to see if taskman.exe or the taskmanager from opening? like it kills the task when the program detects that it is running? Im making a program to lock my computer for my own use and figureing this out would really help. So im looking for a way to get it to loop and look at the running tasks all the time and wait for it to open. Any advice? im new at C# so take it easy please! =)
Y*Live Long And Prosper*Y
|
|
|
|
|
That key sequence can only be trapped by kernel-mode code. It's what's called a secure attention sequence. Your best bet probably is to hide your process (which I don't remember how to do). Either way its probably not a good idea to tamper with the Task Manager operation.
|
|
|
|
|
The only way to stop TaskManager from showing up is to block it using Group Policy. You can't stop it from launching from your code. The absolute best you can do in code is to find the TaskManager process in the process list (see Process class documentation) and terminate the process after it shows up. That means the user will see the TaskManager launch, then quit.
|
|
|
|
|
|
Doing that would be user hostile. Would you want your Task Manager to be disabled? I know I wouldn't.
|
|
|
|
|
I need to write a manager program connect to a remote server to display the status of the server. I have a login form, when i connect successful it will show the main form.
Currently I still don't use the login Form, and now I want to add it to the program rather than using it by default. Below is the code of the Program.cs. How can I add a form ( in this form I have 4 text box for host/port/loginame/pwd and two button Connect and Exit) to the main Form but still do not change the overall structure of the program?
Here is the program.cs
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace MainForm
{
static class Program
{
const string host = "10.0.0.2";
const int port = 5000;
const string loginame = "name";
const string loginpwd = "pwd";
.....
public static AManager manager;
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
checkManagerAPI();
Application.Run(new FrmMain());
}
// checkManagerAPI() region is here:
#region checkManagerAPI()
checkManagerAPI();
{
manager = new AsteriskManager(host, port, loginame, loginpwd);
try
{
manager.Login(); // Login only (fast)
}
catch (Exception ex)
{
Console.WriteLine(ex);
Console.ReadLine();
manager.Logoff();
return;
}
// a lot of code here
}
#end region
}
}
I still don't know how to write the Connect button event clicked: private void btnServerConnect_Click(object sender, EventArgs e). Maybe I still have some difficulties in understanding the structure of the login, the relation with the login form, main form and the file program.cs. How to organize it in an appropriately manner?
Please help me!
Thank you very much!
|
|
|
|
|
**DISCLAIMER** This may or may not be the best way to accomplish this task. This code is based on this article.[^]
static class Program {
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
LoginApplicationContext loctx = new LoginApplicationContext(new Form1(), new LogIn());
Application.Run(loctx);
}
}
public class LoginApplicationContext : ApplicationContext {
private Form appForm;
public LoginApplicationContext(Form app, Form login)
: base(login) {
appForm = app;
}
protected override void OnMainFormClosed(object sender, EventArgs e) {
if (sender is LogIn) {
if ((sender as LogIn).DialogResult == DialogResult.OK) {
base.MainForm = this.appForm;
base.MainForm.Show();
} else {
Application.Exit();
}
} else if (sender is Form1) {
base.OnMainFormClosed(sender, e);
}
}
}
In your login form you'll have to change the Form's DialogResult before you exit. I tested this and it seems to work, though again I don't know it it's the best approach.
Scott P
“It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.”
-Edsger Dijkstra
|
|
|
|
|
Hi,
I have two xml files I added it in to the Property.resource as a embedded resources. how I know that which property is associated which file at run time. means I want file name of respective resource property.
thanx in advance....
|
|
|
|
|
Hi there,
First of all let me say that I tried to find this here in codeproject and google... but I think I'm missing the keywords to find what I want.
What I'm looking for I think it is pretty common.
The thing is... after learning about delegates and threads and trying to implement it in my project I'm still having a freez while the client draws grids.
Let's go to the details:
I have a mainprogram that calls diferent forms from its menu.
One of this forms needs to draw graphics and (Xceed) Grids with lot of data.
The problem: while drawing these graphics and grids, the whole program freezes (all open forms, this form and the mainprogram).
While trying to solve this problem I started researching about delegates, threads and everything else that popped up in the articles. With all I learned I was able to do some things in my project that increased its performance. But in this particular problem, even when the "drawing function" is put in another thread, the mainprogram continues to freez.
I really want to understand why this is happening and how to solve this, so please tell me if I'm wrong.
I'm guessing that the problem happens because the "drawing function" needs to be runned in the same thread as the "form creator" thread, in this case the mainprogram. This way, although the "drawing function" is called through a delegate, its begin starts with "if (this.invokeRequired) this.Invoke" to avoid cross threading problem.
I don't really know in wich thread the "this.Invoke" will execute my "drawing function" but I'm almost certain that is in the mainprogram's one. So it will keep on freezing.
With this in mind I looked in google and here at codeproject the only way I though of to solve this: a way to run the Form in a diferent thread from the mainprogram. Just like as it was a diferent process. This way the "this.Invoke" would call the paralel thread that runs only the Form, and not the whole mainprogram, stopping the freez problem.
I didn't find something that made me do this succesfully and that brings me here.
Can anyone teach me a way to work around this problem? If there is a way to solve this without creating a thread for this form alone, please, I would like to hear it (if creating a thread is a solution at all... I really don't know).
If I said something wrong, I'm sorry, I'm still a jr here. Please tell me so I can learn better about this.
Thanks in advance,
Oscar
|
|
|
|
|
What exactly is taking time? The drawing of data or the loading of data to memory?
I'd be surprised if it's the former - datagrids are usually built to show large amounts of data without freezing.
And yes, you're right, Invoke will execute the delegate passed to it on the UI thread. Can you paste the code (or atleast pseudocode) which you think is taking a long time to complete?
|
|
|
|
|
Hi there Senthil,
First of all thanks for the answer.
What is taking time is the drawing of the data. In our project we use a component called Xceed Grids for better visualization of the data. I dunno if it is quick or if it is slow.
All the data come from a XML that my project receive, all the processing of the document don't take much... the problem is exacly in the function that draws all the grids and the grafics.
The code that takes long is a part of the Xceed Component where we creat the grids.
For instance:
<br />
Agrid.BeginInit();<br />
Agrid.Clear();<br />
<br />
Agrid.SynchronizeDetailGrids = true;<br />
ColumnManagerRow cmrNovo = new ColumnManagerRow();<br />
Agrid.FixedHeaderRows.Add(cmrNovo);<br />
((ColumnManagerRow)Agrid.FixedHeaderRows[0]).AllowColumnReorder = true;<br />
<br />
Agrid.Columns.Add(new DataBoundColumn("Groups"));<br />
Agrid.Columns["Groups"].Fixed = true;<br />
And many more Agrid.Columns.Add
After that We add detailGrids and we must for each column padronize a style.
The foreachs dont take long... almost nothing... the problem is when we run the
"Agrid.Endinit()".
That's the Xceed Grid method that actually draws everything.
If it was only one grid, everything was ok... but we have many grids like that one above to be drawed in sequence and shown in diferent tabs.
Well, did this give some more information?
Thanks in advance!
|
|
|
|
|
Hmm, it's tough then. You can actually create a Form on a different thread, but you must be careful and use Invoke/BeginInvoke when communicating between that form and the rest of the application.
Or you can simply show a form with a progress bar or some visual indicator (animated GIF?) on a different thread - this way, the user will know that the application hasn't hanged.
|
|
|
|
|
Hmmn, that wouldn't be the case..
We do have a progressbar, but it works only while not drawing.
In this part, when drawing.. even windows freezes... thats what I'm most worried about...
Do you know what can freez the application and windows like that?
Thanks again!
Oscar
|
|
|
|
|
Hi,
you should not try and run drawing code in a thread other than the main thread (aka
GUI thread). Instead you should use one or more additional threads to do the slow stuff
(computations, database access, network communication, etc) and from time to time
ask the main thread to adapt the GUI.
You can achieve this in many ways, including:
- explicit instances of the Thread class (good control of what runs when, at which
priority, etc)
- threads from the ThreadPool (less control);
- instances of BackgroundWorker class (it offers a ReportProgress method that
automatically runs on the main thread).
That is the theory. In practice, on top of the above, you'd better group the GUI updates
to avoid many small updates, instead group them (e.g. using a List) and have them execute
periodically. This results in:
- fewer thread switching, hence better performance;
- when organized correctly (e.g. Control.SuspendLayout), better performance and better
visual experience;
- possibly cleaner code.
Grouping updates can be done based on a counter, a timer, or whatever suits the application.
|
|
|
|
|
Hi there Luc, thanks for the answer!
From what've learned I did know that I shouldn't run drawing code from a diferent thread. But the problem is that it is exacly the Drawing code that is freezing the whole program.
Since I can't draw from a diferent thread, I thought about running the whole form (everything about the form) in a diferent thread, as it was a diferent process (a subprogram from my project). This way I thought that I would be able to draw everything in this new thread, and it shouldn't freez the rest of the program.
Is that possible?
From what you posted I got a new idea to increase performance from the drawing function... I'll try to give some updates to the mainthread and see what happends.
I do not know much about controling comunication between threads... the max I know is how to use the CallBack function... this way when one ends, it tells the other.
But I don't know how to give signals from a thread to the main thread while both of them have still more things to do.
Actually, I found it weird that after reading everything I did I didn't find out how to do that.. maybe it is to advanced for me for now. Do you know any specific article that explains how to do this for Jrs?
Thanks again Luc!
Oscar
|
|
|
|
|
Hi Oscar,
oscarderooij wrote: Is that possible?
Simply no. The only way to get a satisfactory behavior is by having all Controls (that
includes Forms) created and operated upon by the single main thread. Everything else
will fail either immediately or eventually. The reason is Controls are not thread-safe,
and all Controls are linked together one way or another (one Form parents and/or owns
another, a Form holds its Controls, etc) so there is no other way than to have a
single thread handle them all.
You really need to use some kind of thread to do computational and/or communication work,
and use a mechanism (such as InvokeRequired/Invoke) to send Control access jobs to the
main thread.
And you may need an interthread communication mechanism. There are classes for
signalling (e.g. AutoResetEvent and ManualResetEvent); and you can use whatever data
structures you choose, you probably need to lock them to prevent other threads to use
inconsistent data while updating (use the lock keyword and some lock object).
|
|
|
|
|
Thanks for the answer Luc,
I see... so there is no way to do that?
That's a problem.
Do you know a good article involving interthread communication?
I'll try looking for something here in codeproject now, but what I mean is if you know a specific good one for beginners or in any other way.
I'll learn how to use that someway.
Thanks again
Oscar
|
|
|
|