Created
February 17, 2018 04:18
-
-
Save immengineer/5513acc169ba60d1a6ef1d017b5328d5 to your computer and use it in GitHub Desktop.
MemoryMappedFile 送信側
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class Form1 : Form | |
{ | |
private MemoryMappedFile mmf; | |
public Form1() | |
{ | |
InitializeComponent(); | |
try | |
{ | |
mmf = MemoryMappedFile.CreateNew("Test", 1024); | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message); | |
this.Close(); | |
} | |
} | |
private void button1_Click(object sender, EventArgs e) | |
{ | |
try | |
{ | |
using (var stream = mmf.CreateViewStream()) | |
using (StreamWriter sw = new StreamWriter(stream)) | |
{ | |
DateTime dt = DateTime.Now; | |
sw.Write(dt.ToString()); | |
} | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message); | |
} | |
} | |
private void Form1_FormClosing(object sender, FormClosingEventArgs e) | |
{ | |
mmf.Dispose(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment