[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 539
  • Last Modified:

Multi session in .net

I am developing a windows application in VS 2008.
In my MDIForm I have two tabs as multi-session and switch.
After logging-in,user will be able to see the MDIForm,if he clicks the Multi-session tab and then click 'Switch',it needs to open a new instance of the application.
I mean two forms running at same time.And it shud be two instances only.Means maximum two forms can be viewed at a time.

How can I do this?
0
johny_bravo1
Asked:
johny_bravo1
  • 9
  • 5
2 Solutions
 
CodeCruiserCommented:
you can use the mdiform.MDIChildren collection to check if the form already exists.
0
 
johny_bravo1Author Commented:
hi thanks for ur comment,
i will give it a try n let u know.I need 2 days for it.
0
 
johny_bravo1Author Commented:
Hi CodeCruiser,
Can u pls tell me how to do this?
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
johny_bravo1Author Commented:
I want two instances of the Application.
It means two MDIForms will be running.
0
 
CodeCruiserCommented:
Oh two instances of application! I thought two instances of a form.
Use the following syntax

Dim procList() As Process = Process.GetProcesses()
Dim i As Integer
Dim AppCount as integer=0
For i = 0 To 20- 1 Step i + 1
   if procList(i).ProcessName = "applicationname" then
      AppCount += 1
   end if
Next
If AppCount < 2 Then
   'Start New Instance
Else
   'Already two instances running
End If

Also make sure that "Make Single Instance Application" box is unticked in project properties in visual studio.
0
 
johny_bravo1Author Commented:
I am getting error
proclist ia a variable but it is used as a method

I have converted it to c#
 Process[] procList = Process.GetProcesses();
            int i = 0;
            int AppCount = 0;
            for (i = 0; i <= 20 - 1; i += i + 1)
            {
                if (procList(i).ProcessName == "applicationname")
                {
                    AppCount += 1;
                }
            }
            if (AppCount < 2)
            {
            }
            else
            {
                //Start New Instance
            }
            //Already two instances running
0
 
johny_bravo1Author Commented:
ohh ok it's my mistake
it should be square brackets.
procList[i].ProcessName
0
 
johny_bravo1Author Commented:
Need your assistance
I am writing above code in Switch click event.
Following are my questions:
1>Why the loop we iterate 19 times.
2>What code should go under MultiSession click
3>What is 'applicationname",is it the solution's name?
0
 
CodeCruiserCommented:
Hi,

1) Its an oversight on my part. It should run to processlist.count - 1. Also change your loop from i += i + 1 to i++
2) All this code should go under multisession click.
3) You need to experiment with this one. I think it would be the exe name but not sure. Use a messagebox to get the name.
0
 
CodeCruiserCommented:
Did you have any success with the code?
0
 
johny_bravo1Author Commented:
Thanks CodeCruiser!!!
It works fine.
Thanks again
0
 
johny_bravo1Author Commented:
Can you pls tell me how can I switch between the forms?
0
 
CodeCruiserCommented:
Glad to be helpful. To switch between the forms, you could use the Form.Activate method.
0
 
johny_bravo1Author Commented:
Ok thanks
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 9
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now