|
You could use for example Process.GetProcessesByName[^] method to find the existing instance and then invoke a method on that instance using reflection. The method could simply set the main forms window state to normal.
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
Mika,Thank you very much!
I have added a line in that else statement above as follows:
Process[] singleInstance = Process.GetProcessesByName( "SingletonApp" );
But in turn ,how shall I write using reflection ?
May you help to write that code followed?
I am looking forward to your reply again!
Thank you very much again!
|
|
|
|
|
I believe that the article Giorgi posted is excellent. Use that and explore the communication. The only thing I would consider in that article is that perhaps IpcChannel could be used instead of TcpChannel.
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
There is a solution to this problem using some unmanaged code as follows:
public static class SingletonApp
{
[DllImport( "user32.dll" )]
static extern bool SetForegroundWindow( IntPtr hWnd );
[DllImport( "user32.dll" )]
static extern bool ShowWindowAsync( IntPtr hWnd , int nCmdShow );
[DllImport( "user32.dll" )]
static extern bool IsIconic( IntPtr hWnd );
const int SW_RESTORE = 9;
static Mutex m_Mutex;
public static void Run( Form mainForm )
{
bool first = IsFirstInstance( );
if( first )
{
Application.ApplicationExit += OnExit;
Application.Run( mainForm );
}
else
{
Process current = Process.GetCurrentProcess( );
Process[ ] procs = Process.GetProcessesByName( current.ProcessName );
IntPtr mainWindowHandle = procs[0].MainWindowHandle;
if( IsIconic( mainWindowHandle ) )
{
ShowWindowAsync( mainWindowHandle , SW_RESTORE );
}
SetForegroundWindow( mainWindowHandle );
}
}
static bool IsFirstInstance( )
{
Assembly assembly = Assembly.GetEntryAssembly( );
string name = assembly.FullName;
m_Mutex = new Mutex( false , name );
bool owned = false;
owned = m_Mutex.WaitOne( TimeSpan.FromSeconds(0) , false );
return owned;
}
static void OnExit( object sender , EventArgs args )
{
m_Mutex.ReleaseMutex( );
m_Mutex.Close( );
}
}
But,there seems to be timing issues yet!
It is sometimes required to double-click executable twice in order to set
that existing instance into the foreground,which cannot be a lot understood!
I strongly expect someone to supply a better solution that is completely managed code!
Thank you very much!
|
|
|
|
|
Hi all,
i'm having problem in custom paging using web application..there is an error saying "Input string was not in a correct format."
Here is my coding..
protected void NavigationLink_Click ( Object sender, CommandEventArgs e )
{
switch ( e.CommandName )
{
case "First":
_currentPageNumber = 1;
break;
case "Last":
_currentPageNumber = Int32.Parse(TotalPages.Text);
break;
case "Next":
_currentPageNumber = Int32.Parse(CurrentPage.Text) + 1;
break;
case "Prev":
_currentPageNumber = Int32.Parse(CurrentPage.Text) - 1;
break;
}
BindData();
}
public void BindData()
{
OdbcConnection myconn;
myconn= new OdbcConnection ("DSN=myodbc2;SERVER=localhost;DATABASE=misdb;UID=root;PORT=3306");
OdbcCommand cmd2 = new OdbcCommand("Select * from registration", myconn);
cmd2.CommandType=CommandType.StoredProcedure;
cmd2.Parameters.Add(new OdbcParameter ("@CurrentPage",OdbcType.Numeric,10)).Value=_currentPageNumber;
cmd2.Parameters.Add(new OdbcParameter("@PageSize",OdbcType.Numeric,10)).Value=DataGrid.PageSize;
cmd2.Parameters.Add(new OdbcParameter("@TotalRecords",OdbcType.Numeric,10)).Direction =ParameterDirection.Output;
try
{
myconn.Open();
DataGrid.DataSource=cmd2.ExecuteReader();
DataGrid.DataBind();
}
finally
{
myconn.Close();
}
CurrentPage.Text=_currentPageNumber.ToString();
Double _totalPages = 1;
if ( !Page.IsPostBack )
{
Int32 _totalRecords = (Int32) cmd2.Parameters["@TotalRecords"].Value;
totalPages = _totalRecords / DataGrid.PageSize;
TotalPages.Text =(System.Math.Ceiling(_totalPages)).ToString();
}
else
{
_totalPages = Double.Parse(TotalPages.Text);
}
if ( _currentPageNumber == 1 )
{
PreviousPage.Enabled = false;
if ( _totalPages > 1 )
{
NextPage.Enabled = true;
}
else
{
NextPage.Enabled = false;
}
}
else
{
PreviousPage.Enabled = true;
if ( _currentPageNumber == _totalPages )
{
NextPage.Enabled = false;
}
else
{
NextPage.Enabled = true;
}
}
}
%#&kmpYrlHSGYG5@#($_+!@!(*JASnjshdk,cm_0ashjhdbn@#$!48mkhfbchsh))^%#W%&@YW7wsdfjw789';'][]\`~JKJQ4$!@#~)-HSKS^&*1)JK12@#@$~!1`DFGkqp][]\]?Zas;EWRG%!@~)(^&BVAG
|
|
|
|
|
Entering something in the CurrentPage field would cause that to happen.
To avoid that, use the int.TryParse method to parse the value so that you can easily detect any illegal input.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
hI,
I cant c TryParse method in program.Got any other solution for this problem..?
%#&kmpYrlHSGYG5@#($_+!@!(*JASnjshdk,cm_0ashjhdbn@#$!48mkhfbchsh))^%#W%&@YW7wsdfjw789';'][]\`~JKJQ4$!@#~)-HSKS^&*1)JK12@#@$~!1`DFGkqp][]\]?Zas;EWRG%!@~)(^&BVAG
|
|
|
|
|
Of course you can't see any TryParse in the program. I said that you should use TryParse in the program.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
ok thank you.
%#&kmpYrlHSGYG5@#($_+!@!(*JASnjshdk,cm_0ashjhdbn@#$!48mkhfbchsh))^%#W%&@YW7wsdfjw789';'][]\`~JKJQ4$!@#~)-HSKS^&*1)JK12@#@$~!1`DFGkqp][]\]?Zas;EWRG%!@~)(^&BVAG
|
|
|
|
|
Hi,
i have a xml file embedded in my project resources. I can read it but i can´t save changes on it, check code bellow
DataSet ds = new DataSet();
ds.ReadXml(Class_Helper.ResourceXml_login, XmlReadMode.ReadSchema);
DataGridView_Administrator.DataSource = ds.Tables[0];
DataRow DataRow_user = ds.Tables[0].NewRow();
DataRow_user["id"] = 10;
DataRow_user["f_name"] = ToolStripTextBox_FName.Text;
DataRow_user["l_name"] = ToolStripTextBox_LName.Text;
DataRow_user["username"] = ToolStripTextBox_Username.Text;
DataRow_user["password"] = ToolStripTextBox_Password.Text;
DataRow_user["role"] = ToolStripComboBox_Role.Text;
ds.Tables[0].Rows.Add(DataRow_user);
ds.WriteXml(Class_Helper.ResourceXml_login,XmlWriteMode.WriteSchema);
DataGridView_Administrator.DataSource = ds.Tables[0];
i can save changes if i use the path way you know?! but i want this way and i really dont know where the codes goes wrong
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|
Of course you can't do this. First of all, resources are Read Only. Second, in order to save those changes, the .EXE file cannot be running because a running .EXE's file is locked by the system. So, in order to update the resource, you have to NOT be running the code.
nelsonpaixao wrote: but i want this way and i really dont know where the codes goes wrong
It's not the code that's going wrong, but your entire concept. You simply cannot do what you want.
|
|
|
|
|
thanks, i didn´t know that.
i will use the path method.
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|
Hi,i am in a problem to scan barcode without an active focus on a textbox. Can anyone help me? Please,do.
|
|
|
|
|
Scanning a barcode is basically the same as using keyboard. Wherever your focus is, that control will receive the input.
This property could be helpful to you: Form.KeyPreview Property[^]
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
When i minimize parent form it minimizes child form too. How can i avoid this behaviour.
Basically I have 2 forms, when a button is clicked on form1 it opens form2.show() but just before opening the form2 i am setting Form1.WindowState = FormWindowState.Minimized and this minimize the child form
I don't want to use form.TopMost becuase this way i form2 cannot be send back.
Thanks
|
|
|
|
|
It's a bit hard to say the problem without seeing the code but few issues:
- If you're using MDI parent (Form1), don't set childs MdiParent property.
- check that Form2 has WindowState set to Normal (or set it after show).
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
I found some softeare, which can display the different texts in different colors.
I am wondering how to realize it in VC#.
thanks.
|
|
|
|
|
|
You can do this with the RichTextbox control.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
I am publishing one project, but it gives the following error message when I run the .exe after installed the project:
(sorry the error message is given in German, in english, shortly, it means that the activation of D:\Publish\WindowsApplication6.application results in an exception. the following error is found:
+ the file C:\Users\Xia\AppData\Local\Temp\Deployment\WRVCRQEQ.H7D\P3Q37RD7.ER9\CSML.dll already exists. I am really confused, CSML.dll is the fill I refered and it is imported into D: disk and has nothing to do with C: disk. moreover, I have checked C:\Users\Xia\AppData\Local\Temp\Deployment, under this I did not find any files and no WRVCRQEQ.H7D\P3Q37RD7.ER9\CSML.dll is found. What does these message mean??
)
INFO ZUR PLATTFORMVERSION
Windows : 6.0.6000.0 (Win32NT)
Common Language Runtime : 2.0.50727.312
System.Deployment.dll : 2.0.50727.312 (rtmLHS.050727-3100)
mscorwks.dll : 2.0.50727.312 (rtmLHS.050727-3100)
dfdll.dll : 2.0.50727.312 (rtmLHS.050727-3100)
dfshim.dll : 2.0.50727.312 (rtmLHS.050727-3100)
QUELLEN
Bereitstellungs-URL : file:///D:/Publish/WindowsApplication6.application
Anwendungs-URL : file:///D:/Publish/WindowsApplication6_1_0_0_16/WindowsApplication6.exe.manifest
IDENTITÄTEN
Bereitstellungsidentität : WindowsApplication6.application, Version=1.0.0.16, Culture=neutral, PublicKeyToken=90e1acef750881e2, processorArchitecture=msil
Anwendungsidentität : WindowsApplication6.exe, Version=1.0.0.16, Culture=neutral, PublicKeyToken=90e1acef750881e2, processorArchitecture=msil, type=win32
ZUSAMMENFASSUNG FÜR ANWENDUNG
* Installierbare Anwendung.
FEHLERZUSAMMENFASSUNG
Es folgt eine Zusammenfassung der Fehler. Details zu diesen Fehlern werden später im Protokoll aufgelistet.
* Die Aktivierung von D:\Publish\WindowsApplication6.application führte zu einer Ausnahme. Folgende Fehlermeldungen wurden entdeckt:
+ Die Datei C:\Users\Xia\AppData\Local\Temp\Deployment\WRVCRQEQ.H7D\P3Q37RD7.ER9\CSML.dll ist bereits vorhanden.
FEHLERZUSAMMENFASSUNG FÜR DIE SPEICHERTRANSAKTION DER KOMPONENTE
Es wurde kein Transaktionsfehler festgestellt.
WARNUNGEN
Während dieses Vorgangs gab es keine Warnungen.
FORTSCHRITTSSTATUS DES VORGANGS
* [14.11.2008 19:39:05] : Die Aktivierung von D:\Publish\WindowsApplication6.application wurde gestartet.
* [14.11.2008 19:39:05] : Das Verarbeiten des Bereitstellungsmanifestes wurde erfolgreich abgeschlossen.
* [14.11.2008 19:39:05] : Die Installation der Anwendung wurde gestartet.
* [14.11.2008 19:39:05] : Das Verarbeiten des Anwendungsmanifestes wurde erfolgreich abgeschlossen.
* [14.11.2008 19:39:06] : Die Anforderung der Vertrauensstellung und die Ermittlung der Plattform sind abgeschlossen.
FEHLERDETAILS
Folgende Fehler wurden bei diesem Vorgang entdeckt.
* [14.11.2008 19:39:09] System.IO.IOException
- Die Datei C:\Users\Xia\AppData\Local\Temp\Deployment\WRVCRQEQ.H7D\P3Q37RD7.ER9\CSML.dll ist bereits vorhanden.
- Quelle: mscorlib
- Stapelüberwachung:
bei System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
bei System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
bei System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
bei System.Deployment.Application.FileDownloader.PatchSingleFile(DownloadQueueItem item, Hashtable dependencyTable)
bei System.Deployment.Application.FileDownloader.PatchFiles(SubscriptionState subState)
bei System.Deployment.Application.FileDownloader.Download(SubscriptionState subState)
bei System.Deployment.Application.DownloadManager.DownloadDependencies(SubscriptionState subState, AssemblyManifest deployManifest, AssemblyManifest appManifest, Uri sourceUriBase, String targetDirectory, String group, IDownloadNotification notification, DownloadOptions options)
bei System.Deployment.Application.ApplicationActivator.DownloadApplication(SubscriptionState subState, ActivationDescription actDesc, Int64 transactionId, TempDirectory& downloadTemp)
bei System.Deployment.Application.ApplicationActivator.InstallApplication(SubscriptionState subState, ActivationDescription actDesc)
bei System.Deployment.Application.ApplicationActivator.PerformDeploymentActivation(Uri activationUri, Boolean isShortcut)
bei System.Deployment.Application.ApplicationActivator.ActivateDeploymentWorker(Object state)
DETAILS ZUR SPEICHERTRANSAKTION DER KOMPONENTE
Es sind keine Transaktionsinformationen verfügbar.
|
|
|
|
|
i dun know german and i won't start learning now ...
Code? Yeah i love it fried together with a glass of wine.
|
|
|
|
|
no problem if you don't know german, I have explained in english for the main problem,
could you please help me to have a look at it. thanks.
|
|
|
|
|
I have two forms. With a button on each.
The click event of the button on the first form is as follows
Form2 form2;
private void button1_Click(object sender, EventArgs e)
{
if (form2 == null)
{
form2 = new Form2();
form2.Show();
}
}
I want the button on the second form to bring back the first form on top with the
BringToFront() method. How do I access the first form as there is no variable for it.
|
|
|
|
|
|
thanx this solves the particular problem.
but I would like to know if there is anyway to get a hold of form1 from form2.
|
|
|
|