|
hi Nick ,
Ur right !. Generics are a welcome addition to the C# language. Perhaps
it will change the way we program our data structures and other stuff.
I was anwsering the questions from a code maintanence point of view.
he was more worried about porting C# 1.x to C# 2.0.
Praseed Pai
www.praseedpai.com
|
|
|
|
|
You won't need to rewrite code. There are no breaking changes in the C# language specification, only new support is added. Almost all the classes supported in the .NET BCL (base class library) will be supported as well (I can't say for sure: there's hundreds of classes).
And don't forget the .NET runs side-by-side. I currently have 1.0 SP2, 1.1, and 2.0 Beta installed. If a managed application that targets 1.0 is installed and .NET 1.0 is installed, it will run against that (unless you redirect). If .NET 1.0 is not installed but 1.1 is, it will run against that (it uses the correct or newer Framework by default). You can control this behavior, however. Read Deploying Applications[^] and Configuring Applications[^] in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Is there a way to make a program that turns of the monitors. In Power Option Properties, you kan set the time from 1 minute to 5 hours, but I would like a program that could turn of my monitors right away, just clicking on an icon - is't for using when i watch films on a projektor, so only monitor 1 an 2 shold be turnd of, not monitor 3 (the projektor).
|
|
|
|
|
|
Well... I have my reasons, so is there a way or not?
|
|
|
|
|
Use WMI to call the SetPowerState function on an instance of the CIM_DesktopMonitor class and pass 6 as the new power state.
Yes, even I am blogging now!
|
|
|
|
|
Hmm.. sounds quite easy, but sorry, I'm a newbee at C# so how do I do that?
|
|
|
|
|
By reading about the System.Management[^] classes and their examples in the .NET Framework SDK. It's the only way to learn.
You can also download the Management Extensions for Visual Studio .NET from the links below, which installs extensions into VS.NET's Server Explorer. You can find the class you want and drag and drop it to your project ot create a typed ManagementObject (supported properties and methods are reflected on the created type), but all this does is provide a wrapper for calling ManagementObject.InvokeMethod , ManagementObject.Get , and ManagementObject.Put .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Wow, I thought there would be something easy as just function.TurnOffMonitor(x) ...
|
|
|
|
|
Its funny how some think someone else should write their code. Is the monitor power button looking like a more feasible implementation for you?
This is easily a case where one can overuse technology. By the time it takes you to figure out how to use the objects in Management you could have just shut off your monitor.
|
|
|
|
|
Ahrghhh.... I just wanted a little help for a something that mattered to me, but I guess I'll have to stick to what what my newbe skills could to come up with:
<br />
private void Form1_Load(object sender, System.EventArgs e)<br />
{<br />
this.Location = new Point(0,0);<br />
this.BackColor = Color.Black;<br />
this.Size = new Size(1280*2, 1024);<br />
}
all through it doesn't turn off the monitors (since my monitors are backlighted), but at least it dims the light. Thank you guys
|
|
|
|
|
PrebKlok wrote:
Thank you guys
What's the bad mood for? Do you not want to learn anything at all? Do you want to be a newbie forever? I suppose, if that's the manner in which you want things handled you should be upset.
- Nick Parker My Blog | My Articles
|
|
|
|
|
Yeah, right next to DoesEverything.MakeMeCoffee() .
If there was a method or something for every possible feature (which is impossible), what would be the point of having programmers?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
what would be the point of having programmers?
Programmers are no longer needed in this world, at least not with the newly released API's containing things like this:
IDevelop id = DeveloperFactory.CreateDeveloper();
id.WriteCompleteApplicationWithNoErrors();
- Nick Parker My Blog | My Articles
|
|
|
|
|
|
Heath Stewart wrote:
I guess maybe I should just be a park ranger out in Washington now that Redmond has decided us programmers are absolete.
Hey, if you did, who could blame you - this[^] view looks awesome.
- Nick Parker My Blog | My Articles
|
|
|
|
|
Well, when you an Megan come up to visit (BTW - have a thread about my new job in my blog) we can take you there! And since I'm absolete now with that pesky DoesEverything class, we'll probably just have a cabin (so it's close to work) there!
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Ok, would this be the way to go?
<br />
object [] arg = {6};<br />
ManagementClass mc = new ManagementClass("Win32_DesktopMonitor");<br />
mc.InvokeMethod("SetPowerState", arg);<br />
problem is that I get the an exception:
An unhandled exception of type 'System.Management.ManagementException' occurred in system.management.dll
Additional information: This method is not implemented in any class
|
|
|
|
|
If you followed my directions (downloaded the WMI extensions for VS.NET) and generated a typed class for the Win32_DesktopMonitor CIMv2 class, you might see immediately what was wrong: SetPowerState takes two parameters: a UInt16 and a DateTime .
Change the first line to object[] arg = {6, DateTime.Now}; and it should work.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hmm... changing the line now gives this execption:
An unhandled exception of type 'System.Management.ManagementException' occurred in system.management.dll
Additional information: Type mismatch
I'm not sure if I understood your direction 100%. After having installed the WMI extensions, I opened the Server Explore and browsed to Servers|MyComputerName|Management Clas|Desktop Settings and then I right clicked and chose "Generate Managed Class"
|
|
|
|
|
That's not the right class. You have to right-click on "Management Classes" and add a new class: root\CIMv2\Win32_DesktopMonitor. Generate a new class from that.
Try object[] arg = new object[] {(ushort)6, DateTime.Now}; . It really shouldn't matter since non-decimal numeric types are implicitly convertible, but it's worth a try. This could present a problem since the method is discovered by the types of parameters, and since just 6 would actually be an int (System.Int32 ), that could be the source of the problem.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
Since the dialog is showing the friendly names, the logical conclusion would be to find something that resembles "Win32_DesktopMonitor", like "Monitors". Add that and generate a class for your project.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hi there,
I developed a small application which will clean up all record(say 4000 or 5000 record) from a dummy table and will insert the updated version of that cleaned record from some other table. This operation is happening oncloseing event handler of that perticular application.
I am using asynchronous programming style for inserting records and synchronous for deletion.
When user click on Exit button, he is actually starting the above mentioned operation.The main problem is he can exit from application once the deletion(synchronous) completes. Here that insertion may or may not on progress depending upon the record size to insert. Why cause insertion is in asynchronous fasion.
In this senario my insertion operation will terminate with inserting few records from actuall collection and will give error say "Communication Error".because the application is closed.
one more thing is i can only do this much operation on the time of application exit not before.
i am including main part of my code block.
//required namespaces
namespace PlanningBoardSystem.GUI
{
public delegate void DataRowInsertionDel(DataRow Dtr);
public class BatchRecordInsertion
{
string DSN=ConfigurationSettings.AppSettings["sourcename"].ToString();
AsaTransaction Astrns;
string Uid="dft";
string Pwd="dft";
AsaConnection Conn;
private DataRow[] Dtable;
public void MyCallBack(IAsyncResult Iar)
{
DataRowInsertionDel DRID=Iar.AsyncState as DataRowInsertionDel;
DRID.EndInvoke(Iar);
}
public void InsertRecord(DataRow Dtr)
{
try
{
//Astrns=Conn.BeginTransaction();
string InsertCmd="Insert into tem values('"+Dtr["process_id"]+"','"+Dtr["record_type"]+"','"+Dtr["process_dec"]+"')";
AsaCommand Asa=new AsaCommand(InsertCmd,Conn);
//Asa.Transaction=Astrns;
Asa.ExecuteNonQuery();
}
catch(Exception Ex)
{
//Astrns.Rollback();
MessageBox.Show(Ex.Message.ToString());
}
}
public BatchRecordInsertion(DataRow[] Dtable)
{
this.Dtable=Dtable;
try
{
Conn=new AsaConnection("Data Source='"+DSN+"'; uid='"+Uid+"'; pwd='"+Pwd+"'");
Conn.Open();
string Delcmd="Delete from tem";
AsaCommand Asa=new AsaCommand(Delcmd,Conn);
//Asa.Transaction=Astrns;
Asa.ExecuteNonQuery();
}
catch(Exception Ex)
{
MessageBox.Show("Error While Opening Database Connection","Database Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
DataRowInsertionDel InsertDel=new DataRowInsertionDel(InsertRecord);
AsyncCallback AsCall=new AsyncCallback(MyCallBack);
for(int j=0;j<<1000;j++)
for(int i=0;i<<5;i++)
{
DataRow Dtr=Dtable[i];
IAsyncResult IAR=InsertDel.BeginInvoke(Dtr,null,null);
}
}
}
}
//here i used one outer loop. don't worry about that. i have only five record in
Dtable. i want few more record.that's why i used that loop//
" How will i handle this sort of situation ?"
" how can i ensure all insertion operations are completed or not " ?
" How i will hold the exit operation upto the completion of all insertion process " ?
"If you know efficient way than this idea of inserting bulk amount of records(no validation required) while keeping performance in mind. Then tell me how ? "
********************
S r e e j i t h N a i r
Bangalore - India
********************
|
|
|
|
|
hi sreejith ,
I have not used ASynchronous method in .NET. Based on my experience
with Win32 threads and Posix thread package , what i feel is
u have retrieve the id of the main thread . then invoke
join method.
join will wait for all the child threads to finish before exiting the parent
process.
This is just a guess . But , i feel it may work
Praseed Pai
www.praseedpai.com
|
|
|
|