I create and write into a memory mapped file using a windows console application. I can read the memory file from another windows console application. It also works fine on the ASP.NET development server.
However, when i try to read the memory mapped file from ASP.NET website hosted on IIS. I get nothing, no exception, no data .
I have hosted my website on IIS7 and using .NET 4.0 framework.
I'm afraid your last post isn't providing sufficient data for me to give you a straight answer.
In the default/main application create mmf (CreateNew) and mutex (new Mutex) when the application starts and dispose both on exit.
In the other application create mmf (OpenExisting) and mutex (Mutex.OpenExisting) when the application starts, use try catch blog to check if the memmory-mapped file exists (if the main application "is running"). Dispose on exit.
Now you will have "connected" memmory. Create MemoryMappedViewStreams and read/write with the help of mutex (WaitOne, ReleaseMutex).
What I susspect about your applications is that each application is creating it's own MMF and they are not connected among each other. Why? Based on your code you are using CreateOrOpen. If MMF doesn't exist that will create a new one, that is why
you don't get error. You simply create a new empty MMF.
Also be carefull with IIS. Applications that are idle for (default setting) 20 min are shut down and restarted when the next client access them.
Please "Mark As Answer" if the post helped you.
mitja.gti | www.mitjagti.com
nexthero
Member
2 Points
3 Posts
memory mapped file in Web
Aug 07, 2012 02:04 AM|LINK
I create and write into a memory mapped file using a windows console application. I can read the memory file from another windows console application. It also works fine on the ASP.NET development server.
However, when i try to read the memory mapped file from ASP.NET website hosted on IIS. I get nothing, no exception, no data .
I have hosted my website on IIS7 and using .NET 4.0 framework.
anyone help me.
mitja.GTI
Star
11157 Points
2094 Posts
Re: memory mapped file in Web
Aug 07, 2012 02:16 AM|LINK
Can you please provide the information about what kind of memory-mapped file you are using and some source code?
mitja.gti | www.mitjagti.com
nexthero
Member
2 Points
3 Posts
Re: memory mapped file in Web
Aug 07, 2012 02:39 AM|LINK
I use .net 4 <using System.IO.MemoryMappedFiles> class : MemoryMappedFile in windows form:
in windows form:
protected MemoryMappedFile mmf; public bool CreateMMF() { try { mmf = MemoryMappedFile.CreateOrOpen(name, length); } catch { return false; } return true; } public void CloseMMF() { mmf.Dispose(); } public bool ReadMMF() { try { using (MemoryMappedViewAccessor mmfAcces = mmf.CreateViewAccessor()) { mmfAcces.ReadArray(0, yxvalue, 0, yx_size); mmfAcces.ReadArray(yx_size, ycvalue, 0, yc_size); } } catch { return false; } return true; } public bool WriteMMF() { try { using (MemoryMappedViewAccessor mmfAcces = mmf.CreateViewAccessor()) { mmfAcces.WriteArray(0, yxvalue, 0, yx_size); mmfAcces.WriteArray(yx_size, ycvalue, 0, yc_size); } } catch { return false; } return true; }in web form:
StringBuilder strVal = new StringBuilder(); MMFManage mmf = new MMFManage(); if (mmf.CreateMMF()) { strVal.Append("create MMF success <br/>"); if (mmf.ReadMMF()) { strVal.Append("read MMF success <br/>"); for(int i =0;i<mmf.YcSize;i++) { strVal.Append("Yc" + i + " : "); strVal.Append(mmf.YcValue[i].ToString() + " ; "); if (i % 10 == 0) { strVal.Append("<br/>"); } } } mmf.CloseMMF(); }mitja.GTI
Star
11157 Points
2094 Posts
Re: memory mapped file in Web
Aug 07, 2012 11:58 AM|LINK
I'm afraid your last post isn't providing sufficient data for me to give you a straight answer.
In the default/main application create mmf (CreateNew) and mutex (new Mutex) when the application starts and dispose both on exit.
In the other application create mmf (OpenExisting) and mutex (Mutex.OpenExisting) when the application starts, use try catch blog to check if the memmory-mapped file exists (if the main application "is running"). Dispose on exit.
Now you will have "connected" memmory. Create MemoryMappedViewStreams and read/write with the help of mutex (WaitOne, ReleaseMutex).
What I susspect about your applications is that each application is creating it's own MMF and they are not connected among each other. Why? Based on your code you are using CreateOrOpen. If MMF doesn't exist that will create a new one, that is why you don't get error. You simply create a new empty MMF.
Also be carefull with IIS. Applications that are idle for (default setting) 20 min are shut down and restarted when the next client access them.
mitja.gti | www.mitjagti.com