I refined your code.
I added two timer and I named it to tmrOpen and tmrClose and set the both property into;
Enabled = false
Interval = 5000
because 1000 is equivalent to 1 second
I also add Start button to start the tmrOpen and I let tmrOpen to start the tmrClose and vice versa.
Hope it helps to you.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Management;
using System.Runtime.InteropServices;
namespace OpenCloseCD_Device
{
public partial class frmCDDrives : Form
{
public frmCDDrives()
{
InitializeComponent();
}
[DllImport("winmm.dll", EntryPoint = "mciSendStringA", CharSet = CharSet.Ansi)]
public static extern int cdKapakAc(string icerik, StringBuilder durum, int deger, IntPtr neKadar);
[DllImport("winmm.dll", EntryPoint = "mciSendStringA", CharSet = CharSet.Ansi)]
public static extern int cdKapakKapat(string icerik, StringBuilder durum, int deger, IntPtr neKadar);
private void btnStart_Click(object sender, EventArgs e)
{
tmrOpen.Enabled = true;
}
private void tmrOpenClose_Tick(object sender, EventArgs e)
{
cdKapakAc("Set cdaudio door open wait ", null, 0, IntPtr.Zero);
tmrClose.Enabled = true;
tmrOpen.Enabled = false;
}
private void tmrClose_Tick(object sender, EventArgs e)
{
cdKapakKapat("Set cdaudio door Closed wait ", null, 0, IntPtr.Zero);
tmrOpen.Enabled = true;
tmrClose.Enabled = false;
}
}
}