|
A guid has a specific format; I wouldn't call the code that youtube uses a "guid", even though they use it for identification.
You can use the random-function to create a random string with a given length, store it in a database, and make sure that you don't issue a double. Would that suffice for identification?
I are troll
|
|
|
|
|
Hi, is possible to get the ThreadId of the window if i know the IdProcess?
thanks. Bye Bye
|
|
|
|
|
Hi,
well...based on the processId you can get the Process , by using Process.GetProcessById(idProcess) . Then, use Threads property of the process object to get all the ProcessThread 's.
Calin
|
|
|
|
|
ok I have understood, but at the moment of lunch Process (Process.Start()), i can get the process id, but not the specific ThreadId of the window. There are many threadId when i call ProcessThread's...how can i find the ThreadId of the window?
thank you Calin.
|
|
|
|
|
May I ask you what do you want achieve with that thread?
Calin
|
|
|
|
|
Ok i try to explain my problem...
I made a sample application: with a button open a folder
(sorry for italian comment but i'm italian)
if (!IdProcessoCartellaDati.HasValue)
{
if (Processo == null)
{
// istanzia il processo
Processo = new Process();
// nome del processo
Processo.StartInfo.FileName = "explorer.exe";
// la cartella da aprire
Processo.StartInfo.Arguments = "C:\\Temp\\Log";
// controllo di eventuali errori
Processo.StartInfo.ErrorDialog = true;
Processo.StartInfo.ErrorDialogParentHandle = Handle;
Processo.StartInfo.UseShellExecute = true;
try
{
// esegue l'apertura della cartella
Processo.Start();
// memorizza l'id del processo
IdProcessoCartellaDati = Processo.Id;
}
catch (Exception)
{
// gli errori sono gestiti da Windows
}
// rilascia le risorse
Processo.Dispose();
}
}
else
{
Processo = Process.GetProcessById(IdProcessoCartellaDati.Value);
// ripristina la finestra (dimensioni)
ShowWindow(Processo.MainWindowHandle, SW_RESTORE);
// e la porta in primo piano
BringWindowToTop(Processo.MainWindowHandle);
}
This solution it's ok, but if i close the application with a explorer open on the specific folder, if i execute the appication again at the first click event Vista open another explorer window (and it's correct) but if i click again ,Vista open another window, and another...
I hope that you have understand my problem.
Thank you.
Bye Bye
|
|
|
|
|
|
|
We have a Database forum - your question has nothing to do with C#
|
|
|
|
|
hello......
i have a datagridview of like 2 coloums and i need to paste the tab seperated data into it the data is like
user address
a b
c d
and i need to copy the above nad paste in thte datagridview. when i copy al this and paste its pasting in a single cell. is there any modification to be done for this to be possible or any other ways of doing this .. thank you.
|
|
|
|
|
there are so many child nodes in parent node. i want on the selection of child node the another form must be open.how can I do this?
|
|
|
|
|
you may use NodeMouseClick to handle the selection event.
Calin
|
|
|
|
|
hello every body,
is there any mechanism in visual studio 2005 and c# to copy the remote server table and update the local database table with that copied table,
please guide me in this topic, step by step to accomplish it
i have sql server 2005 database at local and remote server.
|
|
|
|
|
use bulk copy facility provided by c#.net.
|
|
|
|
|
you could use a datastructure in the client and the server that maps the data and convert to bytes and then decode that data again on the another side . the datastructure may contain the database table coloum names if the both tables on the two sides are same...
|
|
|
|
|
Hey, first post here so sorry if im all over the place here. my previous experience is VB6 and picaxe chips! (lol: "goto main")
I have started my C# (2008) project and made some progress. At the minute i have 3 main classes: Program.cs, SerPort.cs (essentially input into the program) and Output.cs (output from the program). I can deal will the input and output alright, i have an event in serport.cs when data arrives, it grabs the data and sends it to a method in my output.cs that deals with it.
I started this project as a blank C# project as i dont need a form most of the time. I have added code into Program.cs to stick a notify icon in the notify area, fine. The right click menu of this notify icon has 'Exit' and 'Settings'. I have coded the exit event fine, but am having trouble with settings. I need it to open a form which i have made but i need it to do it so the user can only open it once (try right clicking the system clock and clicking properties twice - i want it to work like that)
im pretty new to C# and im picking up as i go along and the problem with showing the form seems to be that the method for the event is a static one (whatever static means), if i try and make it not static, i get an error in my Main method(which is also static), if i try and make my Main method not static it says there isnt a valid static main entry point - GRRR :P
im using this command at the minute: Form Setting = new Settings(); Setting.ShowDialog(); i understand that if i use this in the brackets of showdialog, it should make it modal, but for that my method needs to be non-static. basically i have nothing to own the form, so i can just open as many as i like!
my program is started by "Application.Run();" at the minute, should i make it like a project would be if it were started as a windows forms project and use "Application.Run(form);" and define my notify icon within the form, then hide the form until someone hits the "settings" button? is this bad practise to have the form sat there all the time it isnt being used? should i just stick an if statement before the ShowDialog command to check if the form is already there and activate it if it is (is this what happens when you right click the clock and click properties?)
thanks so much for any help and im sorry this is such an essay, ive just got so many questions and i dont know the conventions. after this is sorted i should be able to deal with the settings (so long as they work in a similar way to VB6 lol) and finish everything off
thanks, Sam
here is my current program.cs, (MediaCenterController is my output.cs):
namespace Video_Duke_Box
{
class Program
{
public Thread trd;
static void Main()
{
if (SerPort.OpenPort())
{
icn = new NotifyIcon();
ContextMenuStrip menu = new ContextMenuStrip();
icn.ContextMenuStrip = menu;
ToolStripMenuItem COMMenuItem = new ToolStripMenuItem("COM Port", null, new EventHandler(COMMenuItem_Click));
ToolStripMenuItem ExitMenuItem = new ToolStripMenuItem("Exit", null, new EventHandler(ExitMenuItem_Click));
ToolStripSeparator separator = new ToolStripSeparator();
menu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { COMMenuItem, separator, ExitMenuItem });
icn.Visible = true;
icn.Icon = Properties.Resources.ehshell_IDI_APP1;
icn.ShowBalloonTip(3000, "Connected", "Duke Box is Connected", ToolTipIcon.Info);
MediaCenterController MCC = new MediaCenterController();
MCC.MediaStateChange += new MediaCenterController.MediaCenterHandler(SerPort.MediaCenter_Running);
MCC.MediaStateChange += new MediaCenterController.MediaCenterHandler(MediaCenter_Running);
Thread trd = new Thread(new ThreadStart(MCC.MediaCenterRunning));
trd.IsBackground = true;
trd.Start();
Application.Run();
}
else
{
}
}
static public void MediaCenter_Running(object MCRObject, MediaCenterEventArg state)
{
if (state.on)
{ icn.Icon = Properties.Resources.ehshell_IDI_APP2; }
else
{ icn.Icon = Properties.Resources.ehshell_IDI_APP1; }
}
static void COMMenuItem_Click(object sender, EventArgs e)
{
Form Setting = new Settings();
Setting.ShowDialog();
}
static void ExitMenuItem_Click(object sender, EventArgs e)
{
icn.Dispose();
SerPort.comport.Close();
Application.Exit();
}
private System.Windows.Forms.NotifyIcon notifyIcon1;
private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
private System.Windows.Forms.ToolStripMenuItem cOMPOrtToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
public ContextMenuStrip menu;
class ControlContainer : IContainer
{
ComponentCollection _components;
public ControlContainer()
{
_components = new ComponentCollection(new IComponent[] { });
}
public void Add(IComponent component)
{ }
public void Add(IComponent component, string Name)
{ }
public void Remove(IComponent component)
{ }
public ComponentCollection Components
{
get { return _components; }
}
public void Dispose()
{
_components = null;
}
}
public static NotifyIcon icn;
}
}
|
|
|
|
|
Ok then, I think I understood some of that
I think there's a keyword in VB 'shared' which means the same as static. Static means things belong to the class rather than to instances of it.
What this means is that anything which is static can only refer to other static things - because you don't have any reference to a particular instance of the class.
As a suggestion to get you going, change all your methods to be non-static and rename the Main to something else. Then create a new static main, and in there instantiate the Program class, then call your old main function - does that make sense? Something like this:
static void Main()
{
Program program = new Program();
program.OldMainFunction();
}
Then you'll be working with an instance of a Program rather than class level...
Regards,
Rob Philpott.
|
|
|
|
|
sweet!
thanks, looks like a bit of work, but i was thinking that i needed to ditch the static at some point, just wasnt sure how :P
so you dont think i need to restructure it? having the form created only when the user presses the button is the right thing to do?
ill have a go at that now, and thanks for taking the time to understand my ramblings!
another problem im going to have when i have finished it all is making the installable, i would love to include some drivers in the install, is this hard to do? (drivers werent written by me)
cheers
sam
|
|
|
|
|
tbh I've never written anything which is invoked from an icon on the task bar so I'm not too sure. It doesn't look quite right to me, but I'm struggling to put my finger on what's wrong.
Suggestion - make the Form a member variable of your Program class. This way, you can only ever have one. If it's set already, you don't need to new it up. Making the form modal may well render your notification tray menu inactive, so I consider going modeless.
As a tip, if you know you're going to be working in Windows (as opposed to a console app) I'd always start a Windows Application project. You'll have to change project settings and add references later on otherwise.
If you're new to this stuff I'd say you were doing pretty well for your first app!
Regards,
Rob Philpott.
|
|
|
|
|
thanks, well i was very pleased i managed to make my own event for windows media center starting (thats that thread starting near application.run()), found the right guide for it and it wasnt too bad: http://www.ondotnet.com/pub/a/dotnet/2003/06/23/progCsharp3.html?page=1[^] i was surprised that creating a loop was the way to check for an event... is this an unpro way of doing it?
i have done VB6 before as i say, but yea just botching code together until it stops giving an error :P the big difference is how many levels u can have: solution, namespace, class, method. its definitely a big difference from a picaxe where you get 14 bytes of data for variables :P
right when you say member variable of my class do you mean using Form.Showdialog(this) ? all this lingo is washing over my head at the minute... or do u mean defining it outside of a method? like private Settings settings;
i think what looks wrong to you is that notifyicons are normally defined in a form? or maybe some icons are defined at the bottom that shouldnt be (they are copied from the form when i was fiddling)
by the way is system.linq needed at the top, everything i create seems to have it, but it just throws up an error so i deleted it :P
so no ideas about including a driver in an install file? is there any command i can use to make windows install a driver? how easy is it to stick custom code into the installer, there were basically 0 with the VB6 package and deployment wizard lol
cheers
|
|
|
|
|
samskiter wrote: i was surprised that creating a loop was the way to check for an event... is this an unpro way of doing it?
Not sure what you mean. Events get fired and have handlers which respond when fired. There's no looping normally.
samskiter wrote: have done VB6 before as i say, but yea just botching code together until it stops giving an error
VB6 is hideous. C# is a dream!
samskiter wrote: member variable of my class
Something like this (usually at the top of the class definition):
private Form _theForm;
samskiter wrote: by the way is system.linq needed at the top
No you don't need that. Delete it, and remove any references to System.Linq in the references folder in the solution. It's a new .NET 3.5 thing and not something to worry about while you're still learning.
Don't really know about the driver bit I'm afraid. Visual Studio does do setup projects but I doubt it supports installing drivers. You'll have to Google around a bit I think.
Regards,
Rob Philpott.
|
|
|
|
|
right, i have tried everything under the sun at the top:
public Settings setting;
private Settings setting;
private Form setting;
public new Settings setting;
but the only way i can make setting.ShowDialog(); work is by using Settings setting = new Settings(); just above it in the click event method.
otherwise i get this error once the program is running (is this a runtime error lol?):
Object reference not set to an instance of an object.
Rob Philpott wrote: Don't really know about the driver bit I'm afraid. Visual Studio does do setup projects but I doubt it supports installing drivers. You'll have to Google around a bit I think.
Cool, will do, its not vital :P the easier the install, the better tho :P
Rob Philpott wrote: VB6 is hideous. C# is a dream!
haha i've been told that but i like it in a way, probs cos im used to it! hmm, this project is my first experience of .NET :P its not so bad
Rob Philpott wrote: Not sure what you mean. Events get fired and have handlers which respond when fired. There's no looping normally.
hmmm, well this is the heart of my event, and this is that that new thread is required for, at the minute it fires the event when calc.exe is started or exited:
public void MediaCenterRunning()
{
for (; ; )
{
Thread.Sleep(1000);
bool onoff = (System.Diagnostics.Process.GetProcessesByName("calc").Length != 0);
Debug.WriteLine(onoff);
if (onoff != on)
{
MediaCenterEventArg StateInfo = new MediaCenterEventArg(onoff);
if (MediaStateChange != null)
{
MediaStateChange(this, StateInfo);
}
}
on = onoff;
}
}
i just fumbled the event together out of code chunks and that guide and a bit of fudging
|
|
|
|
|
please send a code with example?
|
|
|
|
|
please check this[^] article.
Calin
|
|
|
|
|
Hi guys,
Im getting this error :
Min (110) must be less than or equal to max (-1) in a Range object.
when doing some operations on my datatable
System.ArgumentException: Min (110) must be less than or equal to max (-1) in a Range object.
at System.Data.Select.GetBinaryFilteredRecords()
at System.Data.Select.SelectRows()
at System.Data.DataTable.Select(String filterExpression, String sort, DataViewRowState recordStates)
at System.Data.DataTable.Compute(String expression, String filter)
Here is my code:
for (int i = 0; i < list.Count; i++)
{
lt.Add(list[i].ToString()); -------this is the line that causes the error???
maxObject = dtPar.Compute("MAX(Act_doorlooptijd)", "bijelkaar =" + list[i].ToString());
ls.Add(maxObject.ToString());
}
Any idea's what is wrong here?
Thanks
|
|
|
|
|