{"id":983,"date":"2020-01-05T12:26:57","date_gmt":"2020-01-05T17:26:57","guid":{"rendered":"https:\/\/www.baronsoftware.com\/Blog\/?p=983"},"modified":"2020-01-05T12:27:03","modified_gmt":"2020-01-05T17:27:03","slug":"how-to-restart-a-vcl-delphi-application-while-using-a-mutex","status":"publish","type":"post","link":"https:\/\/www.baronsoftware.com\/Blog\/how-to-restart-a-vcl-delphi-application-while-using-a-mutex\/","title":{"rendered":"How to restart a VCL Delphi application while using a Mutex"},"content":{"rendered":"\n<p>How to restart a VCL Delphi application while using a Mutex.  This article puts all of the research in one single page.<\/p>\n\n\n\n<p>Using a mutex prevents multiple application instances from occurring.<\/p>\n\n\n\n<p>You may wonder why would you wish to restart an application.  It doesn&#8217;t mean there was a software defect in the code.  Application settings have changed.<\/p>\n\n\n\n<h2>What is a <strong>mutex<\/strong><\/h2>\n\n\n\n<p>A  <strong><a rel=\"noreferrer noopener\" href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/sync\/using-mutex-objects\" target=\"_blank\">mutex<\/a><\/strong> object is a synchronization mechanism designed to ensure mutually exclusive access to a single resource that is shared among a set of kernel-mode threads. <\/p>\n\n\n\n<p>Using a  <strong><a rel=\"noreferrer noopener\" href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/sync\/using-mutex-objects\" target=\"_blank\">mutex<\/a><\/strong> can ensure that there is only one instance of your application executing.  A unique name should be used when starting the application.<\/p>\n\n\n\n<p>The simplest way is to use your application name and\/or a shorten name that would be unique when creating the  <strong><a rel=\"noreferrer noopener\" href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/sync\/using-mutex-objects\" target=\"_blank\">mutex<\/a><\/strong> .<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.baronsoftware.com\/Blog\/wp-content\/uploads\/2020\/01\/Mutex.fw_.png?w=640&#038;ssl=1\" alt=\"\" class=\"wp-image-984\"\/><figcaption>Simple but true.<\/figcaption><\/figure><\/div>\n\n\n\n<p>  The <strong><a rel=\"noreferrer noopener\" aria-label=\"mutex (opens in a new tab)\" href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/sync\/using-mutex-objects\" target=\"_blank\">mutex<\/a><\/strong> should be released as well as closed.<\/p>\n\n\n\n<h2>Mutex Functions<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>CreateMutex creates a new mutex object with specified name.<\/li><li>OpenMutex will get the handle to already running mutex by its name.<\/li><li>WaitForSingleObject waits for ownership to the mutex.<\/li><li>ReleaseMutex will release ownership of the mutex.<\/li><li>CloseHandle closes the mutex handle and destroys it. <\/li><\/ul>\n\n\n\n<h2> How to insert the logic into a Delphi application <\/h2>\n\n\n\n<p>There is a brilliant piece of code that creates a mutex and allows the application to restart after an update or modification.  You can view the original comments by  <a rel=\"noreferrer noopener\" aria-label=\"read here (opens in a new tab)\" href=\"https:\/\/stackoverflow.com\/questions\/4498276\/restart-delphi-application-programmatically\" target=\"_blank\">clicking here<\/a>. <\/p>\n\n\n\n<p>In Delphi, you can view the source for the program within the IDE.  <\/p>\n\n\n\n<p>Enter the <em><strong>uCreateMutex<\/strong><\/em> unit in the uses section.  Upon starting the application the unit will create the mutex.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>uses\n...\nuCreateMutex in 'uCreateMutex.pas';\n\n{$R *.res}\n\nbegin\n     if uCreateMutex.Active = True then\n     begin\n     ...  Any code for splash screen, data module creation, etc.\n     end; \/\/ end of program.<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>The following code can be placed in a unit so that it is a reusable function.\n\nThe Restart flag must be set to true.\nYou can terminate the application and use ProcessMessages to permit the application to process messages that are currently in the message queue. Only affects this application and nothing else.\n\nfunction ObjectName.restart : boolean;\n begin\n   uCreateMutex.Restart := True;\n   Application.Terminate;\n   Application.ProcessMessages;\n end;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>You can name the unit to whatever you want.  Since the original developer had this name, i decided to use it.\n\nunit uCreateMutex;\ninterface\n\n\/\/ Restart is set to false unless an event triggers a change.\n\/\/ Active is what allows to know if the application is ready to go.\nvar\n  Restart: boolean = false;\n  Active : Boolean = False;\n\nimplementation\n\n\nuses forms, Windows, Messages, SysUtils, Classes, ShellApi, Dialogs;\n\nvar\n  MutexHandle: cardinal;\n  AppName: PChar;\nconst\n  ID = 'ANY UNIQUE NAME YOU WANT';\n\ninitialization\n\/\/ Upon the application starting. The mutex is created with the ID made above.\n  MutexHandle := CreateMutex (nil, False, PChar (ID));\n\n\/\/ The mutex is tested if someone tries to start another instance.\n  if (GetLastError = ERROR_ALREADY_EXISTS) then\n  begin\n\/\/ Fancy message and set the active flag to false.\n    ShowMessage('YO YOUR APPLICATION is running already!');\n    Active := False;\n\/\/ I removed the Halt since that is not a clean way of exiting.\n\/\/ terminating and process any messages in the queue is much cleaner.\n    exit;\n  end\n\/\/ Otherwise the active flag is set to ON.\n  else\n    Active := True;\n\nfinalization\n\/\/ If the Application closes for some reason the mutex is released.\n\/\/ I placed the closing of the mutex handle to clean up the environment.\n  ReleaseMutex(MutexHandle);\n   CloseHandle(MutexHandle);\n\/\/ If the restart flag is set due to any form of update to registry, \n\/\/ settings or the application itself, then it will restart again.\n  if Restart then\n  begin\n    AppName := PChar(Application.ExeName);\n    ShellExecute(0,'open', AppName, nil, nil, SW_SHOWNORMAL) ;\n  end;\n\nend.<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"422\" height=\"114\" data-attachment-id=\"950\" data-permalink=\"https:\/\/www.baronsoftware.com\/Blog\/baronsoftwarelogo_2020-fw\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.baronsoftware.com\/Blog\/wp-content\/uploads\/2019\/08\/BaronSoftwareLogo_2020.fw_.png?fit=422%2C114&amp;ssl=1\" data-orig-size=\"422,114\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"BaronSoftwareLogo_2020.fw\" data-image-description=\"&lt;p&gt;Data Security can no longer be a requirement of the IT Department.  It is vital that the entire company that are within the network be on their utmost watch. The importance today of cyber security cannot be stressed enough.&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Cyber Security&lt;\/p&gt;\n\" data-large-file=\"https:\/\/i0.wp.com\/www.baronsoftware.com\/Blog\/wp-content\/uploads\/2019\/08\/BaronSoftwareLogo_2020.fw_.png?fit=422%2C114&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/www.baronsoftware.com\/Blog\/wp-content\/uploads\/2019\/08\/BaronSoftwareLogo_2020.fw_.png?resize=422%2C114&#038;ssl=1\" alt=\"Baron Software\" class=\"wp-image-950\" srcset=\"https:\/\/i0.wp.com\/www.baronsoftware.com\/Blog\/wp-content\/uploads\/2019\/08\/BaronSoftwareLogo_2020.fw_.png?w=422&amp;ssl=1 422w, https:\/\/i0.wp.com\/www.baronsoftware.com\/Blog\/wp-content\/uploads\/2019\/08\/BaronSoftwareLogo_2020.fw_.png?resize=300%2C81&amp;ssl=1 300w\" sizes=\"(max-width: 422px) 100vw, 422px\" \/><\/figure><\/div>\n\n\n\n<p>This works without any major repercussions on the application. The software code above demonstrates how to cleanly terminate, restart and stop multiple instances.  You can review the original article and apply this freely in your applications.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to restart a VCL Delphi application while using a Mutex. This article puts all of the research in one single page. Using a mutex prevents multiple application instances from occurring. You may wonder why would you wish to restart an application. It doesn&#8217;t mean there was a software defect in the code. Application settings [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rop_custom_images_group":[],"rop_custom_messages_group":[],"rop_publish_now":"initial","rop_publish_now_accounts":[],"rop_publish_now_history":[],"rop_publish_now_status":"pending","_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[5],"tags":[20,271,272,273],"class_list":["post-983","post","type-post","status-publish","format-standard","hentry","category-rad-studio-embarcadero-delphi-development","tag-delphi","tag-mutex","tag-restart","tag-terminate"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to restart a VCL Delphi application while using a Mutex - Baron Software<\/title>\n<meta name=\"description\" content=\"How to restart a VCL Delphi application while using a Mutex. A simple way to do multiple actions in a single Delphi unit.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.baronsoftware.com\/Blog\/how-to-restart-a-vcl-delphi-application-while-using-a-mutex\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to restart a VCL Delphi application while using a Mutex - Baron Software\" \/>\n<meta property=\"og:description\" content=\"How to restart a VCL Delphi application while using a Mutex. A simple way to do multiple actions in a single Delphi unit.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.baronsoftware.com\/Blog\/how-to-restart-a-vcl-delphi-application-while-using-a-mutex\/\" \/>\n<meta property=\"og:site_name\" content=\"Baron Software\" \/>\n<meta property=\"article:published_time\" content=\"2020-01-05T17:26:57+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-01-05T17:27:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.baronsoftware.com\/Blog\/wp-content\/uploads\/2020\/01\/Mutex.fw_.png\" \/>\n<meta name=\"author\" content=\"richard@baronsoftware.com\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"How to restart a VCL Delphi application while using a Mutex\" \/>\n<meta name=\"twitter:description\" content=\"Researching on how to terminate a VCL application while using a Mutex came up with quite a few methods.\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/i0.wp.com\/www.baronsoftware.com\/Blog\/wp-content\/uploads\/2019\/08\/BaronSoftwareLogo_2020.fw_.png?fit=422%2C114&ssl=1\" \/>\n<meta name=\"twitter:creator\" content=\"@Rbaroniunas\" \/>\n<meta name=\"twitter:site\" content=\"@Rbaroniunas\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"richard@baronsoftware.com\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.baronsoftware.com\\\/Blog\\\/how-to-restart-a-vcl-delphi-application-while-using-a-mutex\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.baronsoftware.com\\\/Blog\\\/how-to-restart-a-vcl-delphi-application-while-using-a-mutex\\\/\"},\"author\":{\"name\":\"richard@baronsoftware.com\",\"@id\":\"https:\\\/\\\/www.baronsoftware.com\\\/Blog\\\/#\\\/schema\\\/person\\\/079d370e4230be9d5f75885bb33dd8cd\"},\"headline\":\"How to restart a VCL Delphi application while using a Mutex\",\"datePublished\":\"2020-01-05T17:26:57+00:00\",\"dateModified\":\"2020-01-05T17:27:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.baronsoftware.com\\\/Blog\\\/how-to-restart-a-vcl-delphi-application-while-using-a-mutex\\\/\"},\"wordCount\":309,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.baronsoftware.com\\\/Blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.baronsoftware.com\\\/Blog\\\/how-to-restart-a-vcl-delphi-application-while-using-a-mutex\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.baronsoftware.com\\\/Blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/Mutex.fw_.png\",\"keywords\":[\"Delphi\",\"mutex\",\"Restart\",\"terminate\"],\"articleSection\":[\"Rad Studio Delphi Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.baronsoftware.com\\\/Blog\\\/how-to-restart-a-vcl-delphi-application-while-using-a-mutex\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.baronsoftware.com\\\/Blog\\\/how-to-restart-a-vcl-delphi-application-while-using-a-mutex\\\/\",\"url\":\"https:\\\/\\\/www.baronsoftware.com\\\/Blog\\\/how-to-restart-a-vcl-delphi-application-while-using-a-mutex\\\/\",\"name\":\"How to restart a VCL Delphi application while using a Mutex - Baron Software\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.baronsoftware.com\\\/Blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.baronsoftware.com\\\/Blog\\\/how-to-restart-a-vcl-delphi-application-while-using-a-mutex\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.baronsoftware.com\\\/Blog\\\/how-to-restart-a-vcl-delphi-application-while-using-a-mutex\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.baronsoftware.com\\\/Blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/Mutex.fw_.png\",\"datePublished\":\"2020-01-05T17:26:57+00:00\",\"dateModified\":\"2020-01-05T17:27:03+00:00\",\"description\":\"How to restart a VCL Delphi application while using a Mutex. A simple way to do multiple actions in a single Delphi unit.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.baronsoftware.com\\\/Blog\\\/how-to-restart-a-vcl-delphi-application-while-using-a-mutex\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.baronsoftware.com\\\/Blog\\\/how-to-restart-a-vcl-delphi-application-while-using-a-mutex\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.baronsoftware.com\\\/Blog\\\/how-to-restart-a-vcl-delphi-application-while-using-a-mutex\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/www.baronsoftware.com\\\/Blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/Mutex.fw_.png?fit=356%2C190&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/www.baronsoftware.com\\\/Blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/Mutex.fw_.png?fit=356%2C190&ssl=1\",\"width\":356,\"height\":190},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.baronsoftware.com\\\/Blog\\\/how-to-restart-a-vcl-delphi-application-while-using-a-mutex\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.baronsoftware.com\\\/Blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to restart a VCL Delphi application while using a Mutex\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.baronsoftware.com\\\/Blog\\\/#website\",\"url\":\"https:\\\/\\\/www.baronsoftware.com\\\/Blog\\\/\",\"name\":\"Baron Software\",\"description\":\"Highest Quality Software Developed.\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.baronsoftware.com\\\/Blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.baronsoftware.com\\\/Blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.baronsoftware.com\\\/Blog\\\/#organization\",\"name\":\"Baron Software\",\"url\":\"https:\\\/\\\/www.baronsoftware.com\\\/Blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.baronsoftware.com\\\/Blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/i2.wp.com\\\/www.baronsoftware.com\\\/Blog\\\/wp-content\\\/uploads\\\/2018\\\/01\\\/BaronSoftwareLogo.fw_.png?fit=1920%2C400&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i2.wp.com\\\/www.baronsoftware.com\\\/Blog\\\/wp-content\\\/uploads\\\/2018\\\/01\\\/BaronSoftwareLogo.fw_.png?fit=1920%2C400&ssl=1\",\"width\":1920,\"height\":400,\"caption\":\"Baron Software\"},\"image\":{\"@id\":\"https:\\\/\\\/www.baronsoftware.com\\\/Blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/x.com\\\/Rbaroniunas\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.baronsoftware.com\\\/Blog\\\/#\\\/schema\\\/person\\\/079d370e4230be9d5f75885bb33dd8cd\",\"name\":\"richard@baronsoftware.com\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e5a3cc457a883c420e8af899f2639359d220ae6bfed4587ca7ed17f45ca0c21c?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e5a3cc457a883c420e8af899f2639359d220ae6bfed4587ca7ed17f45ca0c21c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e5a3cc457a883c420e8af899f2639359d220ae6bfed4587ca7ed17f45ca0c21c?s=96&d=mm&r=g\",\"caption\":\"richard@baronsoftware.com\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to restart a VCL Delphi application while using a Mutex - Baron Software","description":"How to restart a VCL Delphi application while using a Mutex. A simple way to do multiple actions in a single Delphi unit.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.baronsoftware.com\/Blog\/how-to-restart-a-vcl-delphi-application-while-using-a-mutex\/","og_locale":"en_US","og_type":"article","og_title":"How to restart a VCL Delphi application while using a Mutex - Baron Software","og_description":"How to restart a VCL Delphi application while using a Mutex. A simple way to do multiple actions in a single Delphi unit.","og_url":"https:\/\/www.baronsoftware.com\/Blog\/how-to-restart-a-vcl-delphi-application-while-using-a-mutex\/","og_site_name":"Baron Software","article_published_time":"2020-01-05T17:26:57+00:00","article_modified_time":"2020-01-05T17:27:03+00:00","og_image":[{"url":"https:\/\/www.baronsoftware.com\/Blog\/wp-content\/uploads\/2020\/01\/Mutex.fw_.png","type":"","width":"","height":""}],"author":"richard@baronsoftware.com","twitter_card":"summary_large_image","twitter_title":"How to restart a VCL Delphi application while using a Mutex","twitter_description":"Researching on how to terminate a VCL application while using a Mutex came up with quite a few methods.","twitter_image":"https:\/\/i0.wp.com\/www.baronsoftware.com\/Blog\/wp-content\/uploads\/2019\/08\/BaronSoftwareLogo_2020.fw_.png?fit=422%2C114&ssl=1","twitter_creator":"@Rbaroniunas","twitter_site":"@Rbaroniunas","twitter_misc":{"Written by":"richard@baronsoftware.com","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.baronsoftware.com\/Blog\/how-to-restart-a-vcl-delphi-application-while-using-a-mutex\/#article","isPartOf":{"@id":"https:\/\/www.baronsoftware.com\/Blog\/how-to-restart-a-vcl-delphi-application-while-using-a-mutex\/"},"author":{"name":"richard@baronsoftware.com","@id":"https:\/\/www.baronsoftware.com\/Blog\/#\/schema\/person\/079d370e4230be9d5f75885bb33dd8cd"},"headline":"How to restart a VCL Delphi application while using a Mutex","datePublished":"2020-01-05T17:26:57+00:00","dateModified":"2020-01-05T17:27:03+00:00","mainEntityOfPage":{"@id":"https:\/\/www.baronsoftware.com\/Blog\/how-to-restart-a-vcl-delphi-application-while-using-a-mutex\/"},"wordCount":309,"commentCount":0,"publisher":{"@id":"https:\/\/www.baronsoftware.com\/Blog\/#organization"},"image":{"@id":"https:\/\/www.baronsoftware.com\/Blog\/how-to-restart-a-vcl-delphi-application-while-using-a-mutex\/#primaryimage"},"thumbnailUrl":"https:\/\/www.baronsoftware.com\/Blog\/wp-content\/uploads\/2020\/01\/Mutex.fw_.png","keywords":["Delphi","mutex","Restart","terminate"],"articleSection":["Rad Studio Delphi Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.baronsoftware.com\/Blog\/how-to-restart-a-vcl-delphi-application-while-using-a-mutex\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.baronsoftware.com\/Blog\/how-to-restart-a-vcl-delphi-application-while-using-a-mutex\/","url":"https:\/\/www.baronsoftware.com\/Blog\/how-to-restart-a-vcl-delphi-application-while-using-a-mutex\/","name":"How to restart a VCL Delphi application while using a Mutex - Baron Software","isPartOf":{"@id":"https:\/\/www.baronsoftware.com\/Blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.baronsoftware.com\/Blog\/how-to-restart-a-vcl-delphi-application-while-using-a-mutex\/#primaryimage"},"image":{"@id":"https:\/\/www.baronsoftware.com\/Blog\/how-to-restart-a-vcl-delphi-application-while-using-a-mutex\/#primaryimage"},"thumbnailUrl":"https:\/\/www.baronsoftware.com\/Blog\/wp-content\/uploads\/2020\/01\/Mutex.fw_.png","datePublished":"2020-01-05T17:26:57+00:00","dateModified":"2020-01-05T17:27:03+00:00","description":"How to restart a VCL Delphi application while using a Mutex. A simple way to do multiple actions in a single Delphi unit.","breadcrumb":{"@id":"https:\/\/www.baronsoftware.com\/Blog\/how-to-restart-a-vcl-delphi-application-while-using-a-mutex\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.baronsoftware.com\/Blog\/how-to-restart-a-vcl-delphi-application-while-using-a-mutex\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.baronsoftware.com\/Blog\/how-to-restart-a-vcl-delphi-application-while-using-a-mutex\/#primaryimage","url":"https:\/\/i0.wp.com\/www.baronsoftware.com\/Blog\/wp-content\/uploads\/2020\/01\/Mutex.fw_.png?fit=356%2C190&ssl=1","contentUrl":"https:\/\/i0.wp.com\/www.baronsoftware.com\/Blog\/wp-content\/uploads\/2020\/01\/Mutex.fw_.png?fit=356%2C190&ssl=1","width":356,"height":190},{"@type":"BreadcrumbList","@id":"https:\/\/www.baronsoftware.com\/Blog\/how-to-restart-a-vcl-delphi-application-while-using-a-mutex\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.baronsoftware.com\/Blog\/"},{"@type":"ListItem","position":2,"name":"How to restart a VCL Delphi application while using a Mutex"}]},{"@type":"WebSite","@id":"https:\/\/www.baronsoftware.com\/Blog\/#website","url":"https:\/\/www.baronsoftware.com\/Blog\/","name":"Baron Software","description":"Highest Quality Software Developed.","publisher":{"@id":"https:\/\/www.baronsoftware.com\/Blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.baronsoftware.com\/Blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.baronsoftware.com\/Blog\/#organization","name":"Baron Software","url":"https:\/\/www.baronsoftware.com\/Blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.baronsoftware.com\/Blog\/#\/schema\/logo\/image\/","url":"https:\/\/i2.wp.com\/www.baronsoftware.com\/Blog\/wp-content\/uploads\/2018\/01\/BaronSoftwareLogo.fw_.png?fit=1920%2C400&ssl=1","contentUrl":"https:\/\/i2.wp.com\/www.baronsoftware.com\/Blog\/wp-content\/uploads\/2018\/01\/BaronSoftwareLogo.fw_.png?fit=1920%2C400&ssl=1","width":1920,"height":400,"caption":"Baron Software"},"image":{"@id":"https:\/\/www.baronsoftware.com\/Blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/Rbaroniunas"]},{"@type":"Person","@id":"https:\/\/www.baronsoftware.com\/Blog\/#\/schema\/person\/079d370e4230be9d5f75885bb33dd8cd","name":"richard@baronsoftware.com","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/e5a3cc457a883c420e8af899f2639359d220ae6bfed4587ca7ed17f45ca0c21c?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/e5a3cc457a883c420e8af899f2639359d220ae6bfed4587ca7ed17f45ca0c21c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e5a3cc457a883c420e8af899f2639359d220ae6bfed4587ca7ed17f45ca0c21c?s=96&d=mm&r=g","caption":"richard@baronsoftware.com"}}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2e6qU-fR","jetpack-related-posts":[{"id":728,"url":"https:\/\/www.baronsoftware.com\/Blog\/almediadev-releases-stylecontrols-version-3-90-delphi\/","url_meta":{"origin":983,"position":0},"title":"AlMediaDev Releases StyleControls Version 3.90 for Delphi","author":"richard@baronsoftware.com","date":"February 9, 2018","format":false,"excerpt":"AlMediaDev Releases StyleControls Version 3.90 for Delphi AlMediaDev has released the latest version 3.90 of StyleControls for the Delphi \/ C++ Builder.\u00a0\u00a0StyleControls is a stable, powerful package (more than 100 components), which uses Classic drawing, system Themes, GDI+ and VCL Styles. This package contains the unique solutions to extend standard\u2026","rel":"","context":"In &quot;Rad Studio Delphi Development&quot;","block_context":{"text":"Rad Studio Delphi Development","link":"https:\/\/www.baronsoftware.com\/Blog\/category\/rad-studio-embarcadero-delphi-development\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.baronsoftware.com\/Blog\/wp-content\/uploads\/2018\/02\/stylecontrols.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1197,"url":"https:\/\/www.baronsoftware.com\/Blog\/why-choose-delphi-for-rapid-application-development\/","url_meta":{"origin":983,"position":1},"title":"Why Choose Delphi for Rapid Application Development","author":"richard@baronsoftware.com","date":"December 13, 2024","format":false,"excerpt":"Delphi is a rapid application development IDE that shortens time for designing and implementing an application for various platforms. Some of the highlights A visual design interface. Fast compilation speeds Strong database integration. A mature component library (VCL). Its ability to maintain legacy systems. Delphi can create high-performance applications with\u2026","rel":"","context":"In &quot;Rad Studio Delphi Development&quot;","block_context":{"text":"Rad Studio Delphi Development","link":"https:\/\/www.baronsoftware.com\/Blog\/category\/rad-studio-embarcadero-delphi-development\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":477,"url":"https:\/\/www.baronsoftware.com\/Blog\/2017-rad-studio-c-builder-delphi-developers-survey\/","url_meta":{"origin":983,"position":2},"title":"2017 Rad Studio (C++ Builder and Delphi) Developers Survey","author":"richard@baronsoftware.com","date":"July 29, 2017","format":false,"excerpt":"2017 Rad Studio Developers Survey The 2017 Embarcadero survey provides the latest information about the programming language Delphi.\u00a0 The survey can be reviewed from Marco Cantu's web site Apparently all versions are still in use since the original design was built as a 32 bit compiler. \u00a0So in theory a\u2026","rel":"","context":"In &quot;Rad Studio Delphi Development&quot;","block_context":{"text":"Rad Studio Delphi Development","link":"https:\/\/www.baronsoftware.com\/Blog\/category\/rad-studio-embarcadero-delphi-development\/"},"img":{"alt_text":"Survey","src":"https:\/\/i0.wp.com\/www.baronsoftware.com\/Blog\/wp-content\/uploads\/2017\/07\/2017survey_01-300x115.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":88,"url":"https:\/\/www.baronsoftware.com\/Blog\/delphi-tip-if-you-get-unit-vcl-filectrl-is-specific-to-a-platform-warning\/","url_meta":{"origin":983,"position":3},"title":"Delphi Tip if you get &#8220;unit vcl.filectrl is specific to a platform&#8221; warning","author":"richard@baronsoftware.com","date":"February 10, 2015","format":false,"excerpt":"The warning \"unit vcl.filectrl is specific to a platform\" is Delphi's way of giving you heads up that the addition of one of the few components such as TDRIVECOMBOBOX will not work on other platforms besides a Windows environment. To remove this type of warning during the application build cycle\u2026","rel":"","context":"In &quot;Rad Studio Delphi Development&quot;","block_context":{"text":"Rad Studio Delphi Development","link":"https:\/\/www.baronsoftware.com\/Blog\/category\/rad-studio-embarcadero-delphi-development\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":755,"url":"https:\/\/www.baronsoftware.com\/Blog\/find-glyphs-icons-delphi-application-menu-toolbar\/","url_meta":{"origin":983,"position":4},"title":"Where to Find Glyphs and Icons for a Delphi Application, Menu, Toolbar","author":"richard@baronsoftware.com","date":"February 11, 2018","format":false,"excerpt":"Where to Find Glyphs and Icons for a Delphi Application, Menu, Toolbar When using the latest version of Embarcadero's Rad Studio and you wish to use a BitBtn or Speedbutton on your form you will need to locate where a glyph resides.\u00a0 A glyph is simply a bitmap image that\u2026","rel":"","context":"In &quot;Rad Studio Delphi Development&quot;","block_context":{"text":"Rad Studio Delphi Development","link":"https:\/\/www.baronsoftware.com\/Blog\/category\/rad-studio-embarcadero-delphi-development\/"},"img":{"alt_text":"Delphi","src":"https:\/\/i0.wp.com\/www.baronsoftware.com\/Blog\/wp-content\/uploads\/2016\/01\/Embarcadero-Logo-e1467218648875.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":438,"url":"https:\/\/www.baronsoftware.com\/Blog\/happy-birthday-delphi-22-years-counting\/","url_meta":{"origin":983,"position":5},"title":"Happy Birthday to Delphi at 22 years and counting","author":"richard@baronsoftware.com","date":"February 14, 2017","format":false,"excerpt":"Happy Birthday to Delphi at 22 years and counting Well with the next release, \"Godzilla - Tokyo\" currently in beta testing and getting prepared to support Linux servers, there is no better way then to shout out a happy birthday to Delphi. Delphi History Delphi was originally developed by Borland\u2026","rel":"","context":"In &quot;Rad Studio Delphi Development&quot;","block_context":{"text":"Rad Studio Delphi Development","link":"https:\/\/www.baronsoftware.com\/Blog\/category\/rad-studio-embarcadero-delphi-development\/"},"img":{"alt_text":"Delphi for Linux","src":"https:\/\/i0.wp.com\/www.baronsoftware.com\/Blog\/wp-content\/uploads\/2016\/12\/LinuxIsComing-300x300.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.baronsoftware.com\/Blog\/wp-json\/wp\/v2\/posts\/983","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.baronsoftware.com\/Blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.baronsoftware.com\/Blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.baronsoftware.com\/Blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.baronsoftware.com\/Blog\/wp-json\/wp\/v2\/comments?post=983"}],"version-history":[{"count":1,"href":"https:\/\/www.baronsoftware.com\/Blog\/wp-json\/wp\/v2\/posts\/983\/revisions"}],"predecessor-version":[{"id":985,"href":"https:\/\/www.baronsoftware.com\/Blog\/wp-json\/wp\/v2\/posts\/983\/revisions\/985"}],"wp:attachment":[{"href":"https:\/\/www.baronsoftware.com\/Blog\/wp-json\/wp\/v2\/media?parent=983"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.baronsoftware.com\/Blog\/wp-json\/wp\/v2\/categories?post=983"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.baronsoftware.com\/Blog\/wp-json\/wp\/v2\/tags?post=983"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}