|
My pleasure. MSDN is a large place where things get lost easily
I are Troll
|
|
|
|
|
I have tried this with the code:
dt.Columns.Add("Pair");
dt.Columns["Pair"].ReadOnly = true;
dt.Columns.Add("Last");
dt.Columns.Add("TimeStamp");
dt.Columns["TimeStamp"].ReadOnly = true;
The Pairs column remains readonly, yet the TimeStamp column allows the text to be manipulated, then throws an error that the column is read only once the focus has left the cell...
|
|
|
|
|
The "dt" prefix suggests that you're setting the Columns of the DataTable to readonly. The link that I posted set the readonly property on the Columns of a DataGridView . Both are possible, and seem to work correctly from a test-project;
public Form1()
{
InitializeComponent();
DataGridView dgv = new DataGridView();
dgv.Dock = DockStyle.Fill;
Controls.Add(dgv);
DataTable dt = new DataTable();
dt.Columns.Add("Pair");
dt.Columns.Add("Last");
dt.Columns.Add("TimeStamp");
dt.Rows.Add();
dgv.DataSource = dt;
dgv.Columns[0].ReadOnly = true;
dgv.Columns[2].ReadOnly = true;
}
Uncomment the "dt" lines if you want to test that variant
I are Troll
|
|
|
|
|
Assuming that you are asking about a WPF/SilverLight component, all items in GridView retain attributes of their cell templates. For example, if you used TextBlock in your data template, you'd set its IsEnabled property to "False" to gray out the column.
DataGrid, on the other hand, lets you set properties on individual columns (very much in line with what you described). For example, DataGridTextColumn and DataGridTemplateColumn have an IsReadOnly property that you can set in XAML.
EDIT: It looks like you were not talking about WCF after all
|
|
|
|
|
It writes to the log file every 2 seconds, so I know it is looping, but it does not stop the shutdown executable from running. However if I loop it with a batch file it works perfect? Is there a way to have the command text write to the console window as well?
Thanks for reading.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
while (true)
{
System.Diagnostics.ProcessStartInfo shutDownBlocker = new ProcessStartInfo();
shutDownBlocker.FileName = @"c:\windows\system32\shutdown.exe";
shutDownBlocker.WindowStyle = ProcessWindowStyle.Normal;
shutDownBlocker.Arguments = " /a";
shutDownBlocker.CreateNoWindow = false;
Thread.Sleep(2000);
File.AppendAllText(@"c:\temp\shutdownlog.txt", "ran command" + System.Environment.NewLine);
}
}
}
}
|
|
|
|
|
As per my understanding to the question, you have only created the object of ProcessStartInfo and assigned some values to it.
you need to call the Process.Start() API of Process class with object of ProcessStartInfo as a parameter.
Then and only then your 'shutdown.exe' will start and perform its duty.
Refer this link for more details and example http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.aspx[^]
If you have further query, please elaborate it.
Hope this helps!!!
Praveen Raghuvanshi
Software Developer
|
|
|
|
|
Hi Praveen, that looks to be my problem, thank you very much.
I'm trying to incorporate it into a service I am building and it just does not work. I am probably overlooking something again, if you have any ideas, I'd love to hear them.
Thank you again for the help.
using System;
using System.Diagnostics;
using System.ServiceProcess;
using System.Threading;
using System.Windows.Forms;
namespace WindowsService
{
class WindowsService : ServiceBase
{
Thread thread = new Thread(new ThreadStart(shutDownBlocker));
public WindowsService()
{
this.ServiceName = "AllinOneService";
this.EventLog.Log = "Application";
this.CanHandlePowerEvent = true;
this.CanHandleSessionChangeEvent = true;
this.CanPauseAndContinue = true;
this.CanShutdown = true;
this.CanStop = true;
shutDownBlocker();
thread.Start();
}
static void Main()
{
ServiceBase.Run(new WindowsService());
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
protected override void OnStart(string[] args)
{
base.OnStart(args);
}
protected override void OnStop()
{
base.OnStop();
}
protected override void OnPause()
{
base.OnPause();
}
protected override void OnContinue()
{
base.OnContinue();
}
protected override void OnShutdown()
{
base.OnShutdown();
}
protected override void OnCustomCommand(int command)
{
base.OnCustomCommand(command);
}
protected override bool OnPowerEvent(PowerBroadcastStatus powerStatus)
{
return base.OnPowerEvent(powerStatus);
}
protected override void OnSessionChange(SessionChangeDescription changeDescription)
{
base.OnSessionChange(changeDescription);
}
private static void shutDownBlocker()
{
while (true)
{
try
{
System.Diagnostics.ProcessStartInfo shutDownBlocking = new ProcessStartInfo();
shutDownBlocking.CreateNoWindow = true;
shutDownBlocking.FileName = @"c:\windows\system32\shutdown.exe";
shutDownBlocking.WindowStyle = ProcessWindowStyle.Hidden;
shutDownBlocking.Arguments = "/a";
Process.Start(shutDownBlocking);
Thread.Sleep(500);
}
catch (Exception ex)
{
}
}
}
}
}
|
|
|
|
|
You are missing System.Diagnostics.Process.Start(shutDownBlocker);
|
|
|
|
|
On top of what the other people said, this little technique you're using will only stop a shutdown IF it was initiated with the SHUTDOWN.EXE command. If you shutdown the system with Start -> Shutdown, or some other method other than Shutdown.exe, this code won't do a thing to stop it.
|
|
|
|
|
After a quick search I found this
Often people try to code complex soluting when the OS already give them the option...
|
|
|
|
|
Hi,
That's an interesting assumption, but the only thing that has in common with what I am trying to do is the word "shutdown" is in both posts.
|
|
|
|
|
Hi Dave,
I agree ... this is for remote/local calls to that executable on a box via global patches, that needs controlled shutdowns/reboots, but that cannot be in its own AD collection with separate gps.
|
|
|
|
|
Unless your patches use SHUTDOWN.EXE to shutdown/restart the machine, your code is still not going to work.
The patch has to be told to NOT shutdown the machine, but that's only if the patch supports some kind of switch to tell it not to do so.
|
|
|
|
|
Dave,
I tested it with a simple batch file that looped with "shutdown /a" every 1000ms and it worked.
If you think there is something else that should be coded for as a due diligence type of thing, I'd be happy to incorporate that into the code. Let me know.
|
|
|
|
|
I told you this only works if the shutdown was initiated with SHUTDOWN.EXE. If something calls ExitWindowsEx, SHUTDOWN /A will NOT abort it. If it works with your test patch, great, that's one test. I can pretty much guarantee that it won't work in all cases. If your patch uses SHUTDOWN.EXE to restart the machine, you'll be OK. Not great, but OK. There will be those cases where your 1 second delay (or whatever you use) will be sufficient for the patch to call SHUTDOWN.EXE and shutdown actually gets around to calling ExitWindowsEx before your piece of code can launch SHUTDOWN /A.
|
|
|
|
|
Hello
Could someone tell me please: How to create a Module class in C# similar to VB .NET?
Thanks in advance...
kind regards
lapeci
|
|
|
|
|
There's no such thing : create a public static class
Cheers
If you can read this, you don't have Papyrus installed
|
|
|
|
|
Hi Estys
Thanks for your reply.
I have have created the static class but im having a problem on one of my method inside this class maybe you can tell me if I'm missing something.
Here is the code of that method...
public override bool Equals(object obj)
{
UserClient temp = obj;
return (userPass == temp.userPass);
}
The error it gives me is:
Can not implicitly convert type 'object' to UserClient...
The UserClient is the static class...
Thanks again in advance
kind regards
lapeci
|
|
|
|
|
Try this :
public override bool Equals(object obj)
{
UserClient temp = (UserClient)obj;
return (userPass == temp.userPass);
}
You were missing casting. You have to explicitly cast the object to UserClient.
|
|
|
|
|
This is not safe, you risk exceptions if the cast fails.
Cheers
If you can read this, you don't have Papyrus installed
|
|
|
|
|
Hi Pravin
Thanks for your reply.
Could you please help me convert this Module of VB .NET in to C# ...
Module UserLoginOptionModule
Public CustomerList As ArrayList = New ArrayList()
Public ordersMap As Collections.Hashtable = New Hashtable()
' Global variables
Public UserNameVal As String
Public UserSurnameVal As String
Public UserTypeVal As String
Public UserRoomNoVal As String
Public UserNoOfCovers As String
Public UserId As Integer
Public CurrCustomer As Customer
End Module
thanks in advance
kind regards
lapeci
|
|
|
|
|
static class UserLoginOptionModule
{
public static ArrayList CustomerList = new ArrayList();
public static System.Collections.Hashtable ordersMap = new Hashtable();
public static string UserNameVal;
public static string UserSurnameVal;
public static string UserTypeVal;
public static string UserRoomNoVal;
public static string UserNoOfCovers;
public static int UserId;
public static Customer CurrCustomer;
} There is an online converter here[^] which will take most of the pain out of things. I sometimes use it to generate VB for Q&A answers.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Estys is right: use as instead:
public override bool Equals(object obj)
{
UserClient temp = obj as UserClient;
if (temp != null)
{
return (userPass == temp.userPass);
}
return false;
} You can also do it with is , but I prefer an explicit null check as it ensures the parameter is valid as well:
public override bool Equals(object obj)
{
if (obj is UserClient)
{
UserClient temp = (UserClient) obj;
return (userPass == temp.userPass);
}
return false;
}
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
You can't instantiate static classes, You can only refer to it's properties and methods.
So
UserClient temp = obj;
is wrong.
The error you're getting has nothing to do with that however.
UserClient temp = obj as UserClient;
if (!temp == null) { .. }
would work, but not for a static class. Similarly, in VB you can't 'create' a module.
see http://msdn.microsoft.com/en-us/library/79b3xss3(v=vs.80).aspx[^]
[edit] maybe it would work, never tried such a thing [/edit]
Cheers
If you can read this, you don't have Papyrus installed
|
|
|
|
|
Hi, You can not create Module class in C#.net as it was there in VB6 and now in VB.NET.
It may be because microsoft wanted to be purely Object oriented with C#. Instead you can create a Class Library for common functions and use it.
|
|
|
|