Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello guys,
I have 3 or more windows form that popup in similar Time , i want to close this form by a unique key
assume each form has a guid that we can know them.

i receive a request in business layer and i want to close form

seem be easy! :)

i use a timer like this but i cant access from business layer

What I have tried:

C#
public partial class LinkNotificationMessage : Form
    {
        System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
        private readonly VMSCore.ViewModel.LinkNotificationMessage Message;
        public LinkNotificationMessage(VMSCore.ViewModel.LinkNotificationMessage message)
        {
            Message = message;
            InitializeComponent();
            InitiateMessage();

            timer.Tick += new EventHandler(OnTimedEvent);
            timer.Interval = message.TimeToLive;
            timer.Enabled = true;

        }

        private void InitiateMessage()
        {
            lblMessage.Text = Message.Message;
            btnLink.Text = Message.linkText;
            lblMessage.Text = DateTime.Now.Minute.ToString() + " "+  DateTime.Now.Second.ToString();
        }

        private void btnLink_Click(object sender, EventArgs e)
        {
            var processStartInfo = new System.Diagnostics.ProcessStartInfo();
            processStartInfo.UseShellExecute = true;
            processStartInfo.FileName = Message.Link; ;
            System.Diagnostics.Process.Start(processStartInfo);
            Close();
            
        }

        private void OnTimedEvent(object source, EventArgs e)
        {
            this.Close();
            timer.Stop();
        }
    }
Posted
Updated 20-Aug-22 18:47pm
v2

1 solution

Your Business Layer should have nothing to do with the presentation layer - it shouldn't even know that it's a Winforms app, a Console app, or a web app. Heck, the BL may not even by running on the same computer as the PL or DL!

Instead, if the BL (or DL) has rules which require an action from higher layers, they should provide Events that higher layers can handle. The event handler then closes teh forms as needed so that OOPs principles aren't compromised.

Have a look here: Transferring information between two forms, Part 2: Child to Parent[^] - it's designed for forms, but it's exactly the same process for layers (and the separate Projects / Assemblies they are made of)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900