|
If you say
socket.Blocking = true
then it is more like Synchronous call, looks like you might require Asynchronous environment as you are trying to handle multiple clients.
|
|
|
|
|
|
i am writing some code, if will act different ways on x64 and x86,
does there is a way to justify the code is compiled by x64 or x86,
as i know i cpp i can use
#ifdef __x64
doA
#elif __x86
doB
#endif
|
|
|
|
|
sorry, but why the hell is your first name "Dracula"?
dev
|
|
|
|
|
just for fun.
there is a movie with this name, and some games
|
|
|
|
|
Check the Operation System Name.In X64 Bit Operation System have X64.
mailto: anubhava.prodata@gmail.com
|
|
|
|
|
for now, i am just using the return IntPtr.Size == 8,
|
|
|
|
|
Good People,
I have a log file that I open to write to while my application is running. If I don't close it and my application exits, can I write to it again when my application opens? If I don't close it and my application exits, will it cause operating system instability or any other problems?
Thanks,
Blitz
|
|
|
|
|
Hi,
a Windows process cleans up after itself upon exit, no matter what.
So your old log file will be closed; it may however not contains the latest log entries, since these probably were still in some buffers somewhere.
That is why I often implement a log method as an open-for-append, write, close sequence, increasing the probability the last entries are in the file; they probably are the ones you want to see when things suddenly go wrong! Of course open/write/close is slower than a simple write, so you may want to switch back to a simple write in a release build.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Thanks Luc, I appreciate the information.
|
|
|
|
|
How can I read the photo taken date(not the created date or modified date). I found on Google that can be do by propertyItems. There’s no date taken property in Property items.
Is there any possible way to read the photo taken date???
A S E L A
|
|
|
|
|
Some file formats (including JPEG) allow for a lot of metadata, and most camera's seem to provide at least some of these pieces of information.
Here is some code that may be useful to you; I will not provide support on it though.
string s=readImageProperty(image, 0x132);
log("datetime="+s);
DateTime exposureDate=ParseExposureDate(s, equipModel);
log("Exposure DateTime = "+DateToString(exposureDate, false, ""));
private static string readImageProperty(Image image, int ID) {
try {
PropertyItem pi=image.GetPropertyItem(ID);
if(pi!=null) {
if(pi.Type==2) {
return ASCIIencoding.GetString(pi.Value, 0, pi.Len-1);
}
if(pi.Type==5) {
byte[] bb=pi.Value;
uint uNominator=BitConverter.ToUInt32(bb, 0);
uint uDenominator=BitConverter.ToUInt32(bb, 4);
if(uDenominator==1) return uNominator.ToString();
return uNominator.ToString()+"/"+uDenominator.ToString();
}
}
} catch {
}
return null;
}
private static DateTime ParseExposureDate(string exposure, string equipModel) {
DateTime dt=DateTime.MinValue;
bool OK=false;
if(!OK) {
OK=DateTime.TryParseExact(exposure, "yyyy:MM:dd HH:mm:ss",
null, DateTimeStyles.None, out dt);
}
log("ParseExposureDate: \""+exposure+"\" >>> "+dt);
return dt;
}
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
|
browsing the documentation for 10 seconds would reveal the namespace.
I am not in the spoon feeding business, I try to provide added value.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
hello (First of all sorry about long stack trace)
I ran into this problem with System.Data.OracleClient - "System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
I checked the following, none resolved the problem:
(a) Make sure M$ DTC startup automatic
(b) C:\oraclexe\app\oracle\product\10.2.0\server\NETWORK\ADMIN\sqlnet.ora
Change from:
SQLNET.AUTHENTICATION_SERVICES = (NTS)
To:
SQLNET.AUTHENTICATION_SERVICES= (NONE)
(c) Set OracleConnection.Unicode to true, i.e. add the following to connection string
Unicode=true;
(d) Be careful with LONG, LONG RAW, OBJECT, XMLTYPE - try comment out first if any.
REF: http://www.devart.com/forums/viewtopic.php?p=42223&sid=603c2d8bf01329ec2e98df036d5ef2da
I can't find anything "funny" with my Person's table.
<br />
CREATE TABLE PERSON (<br />
Id numeric(19,0) NOT NULL,<br />
FirstName nvarchar2 (50) NOT NULL,<br />
MiddleName nvarchar2 (50) NULL,<br />
LastName nvarchar2 (50) NOT NULL,<br />
PrimaryEmail nvarchar2 (190) NULL,<br />
PersonType int default 1 NOT NULL, <br />
CreateDate date default sysdate NULL, <br />
CreatedBy numeric(19,0) default -1 NULL,<br />
LastUpdate date NULL,<br />
LastUpdateBy numeric(19,0) NULL,<br />
<br />
CONSTRAINT PK_PERSON PRIMARY KEY (Id),<br />
CONSTRAINT UK_PERSON_PRIMARYEMAIL UNIQUE (PrimaryEmail)<br />
)<br />
And my NHibernate mapping file (Googled a bit don't think it is problem with NHibernate, also this Save works fine with MySQL and M$SQL, only Oracle making trouble):
<br />
class name="Person" table="Person"<br />
id name="Id" column="Id" type="Int64" unsaved-value="0"<br />
generator class="sequence"<br />
param name="sequence" SYSTEMUSER_SEQ /param<br />
/generator<br />
/id<br />
property name="PrimaryEmail" column="PrimaryEmail" type="String(255)"/<br />
<br />
property name="Type" column="PersonType" type="Int32"/<br />
<br />
component name="Name" class="xxxxx.Util.Name"<br />
property name="FirstName" column="FirstName" type="String(50)" /<br />
property name="MiddleName" column="MiddleName" type="String(50)" /<br />
property name="LastName" column="LastName" type="String(50)" /<br />
/component<br />
component name="BasicAudit" class="xxxxx.Util.Security.BasicAudit"<br />
property name="CreateDate" column="CreateDate" type="DateTime"/<br />
property name="CreatedBy" column="CreatedBy" type="Int64"/<br />
property name="LastUpdate" column="LastUpdate" type="DateTime"/<br />
property name="LastUpdateBy" column="LastUpdateBy" type="Int64"/<br />
/component<br />
joined-subclass name="xxxxx.Util.Security.SystemUser" table="SystemUser"<br />
key column="PersonId" /<br />
property name="Logon" column="Logon" type="String(50)" /<br />
property name="PasswdHash" column="PasswdHash" type="Int32"/<br />
/joined-subclass<br />
/class<br />
And here's application code:
<br />
public virtual long Save(ref IGenericTO oPerson)<br />
{<br />
...<br />
<br />
try<br />
{<br />
<br />
using (oScope = new TransactionScope())<br />
{<br />
DBSession.Flush();<br />
nGeneratedId = (long)DBSession.Save(oPerson);<br />
DBSession.Flush();<br />
<br />
... other database operation done in ADO.NET ...<br />
<br />
oScope.Complete();<br />
}<br />
}<br />
catch (Exception ex)<br />
{<br />
....Util.ApplicationException.Throw("Save failed", null, oPerson.ToString(), ex);<br />
}<br />
<br />
return nGeneratedId;<br />
}<br />
(e) M$ Hot fix - as suggested by http://forums.asp.net/p/675515/675515.aspx
I downloaded "303312_intl_i386_zip.exe " from following M$ URL.
Unfortunately on my XP box with:
* .NET 3.5 SP1
* Oracle 10g Express
* System.Data.OracleClient Runtime version v2.0.50727
I had the following error while trying to install the fix:
"The upgrade patch canno be installed by the Windows Installer service because the program to be upgraded may be missing, or the upgrade patch may update a different version of the program. Verify that the program to be upgraded exists on your computer and that you have the correct upgrade path."
The fix does indicate that it is intended for .NET 2.0 however:
"Article ID: 923028 - Last Review: March 25, 2009 - Revision: 4.0 FIX: Error message when you run a .NET Framework 2.0 Remoting application: "Unhandled Exception: System.AccessViolationException"
Download fix:
https://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=6003&wa=wsignin1.0
Any suggestion? Help!
REF:
http://forums.oracle.com/forums/thread.jspa?threadID=415053&tstart=0
http://www.devart.com/forums/viewtopic.php?p=42223&sid=603c2d8bf01329ec2e98df036d5ef2da
http://forums.asp.net/p/675515/675515.aspx
Sorry for long stack trace
<br />
2009-04-09 07:31:24,609 [10] ERROR SimpleConsoleTest - xxxxx.Util.ApplicationException Exception context: xxxxx.Util.ApplicationExceptionContext, Subject: Save failed, Description: xxxxx.Util.Person, Id:-1, Name:xxxxx.Util.Name, FirstName:John, MiddleName:, LastName:Kennedy, PrimaryEmail:john.kennedy@gmail.com, Type:undefined, GenericObj:object type: xxxxx.Util.Generic.GenericObject, object name: , object classifier: Person, TypeName: xxxxx.Util.Person, DAOTypeName: xxxxx.Util.PersonDAO, Util, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, DAOCreateInstanceArg: , CreateDate: 4/9/2009 7:31:19 AM, Properties: , Parents count:0, Children:, DatabaseInitiated: False, BasicAudit:xxxxx.Util.Security.BasicAudit, CreateDate:4/9/2009 7:31:19 AM, CreatedBy:-1, LastUpdate:1/1/1753 12:00:00 AM, LastUpdateBy:-1, StackTrace: at xxxxx.Util.ApplicationException.Throw(String strSubject, String strSummary, String strDescription, Exception oInnerException) in C:\dev\xxxxx\NET3.0\Util\ApplicationException.cs:line 176<br />
at xxxxx.Util.PersonDAO.Save(IGenericTO& oPerson) in C:\dev\xxxxx\NET3.0\Util\PersonDAO.cs:line 349<br />
at xxxxx.NUnitTest.TestDAOUtil.TestSaveAndSelectByKey(IGenericTO& o) in C:\dev\xxxxx\NET3.0\NUnitTest\TestDAOUtil.cs:line 349<br />
at xxxxx.NUnitTest.TestDAOUtil.TestDAO(Boolean bTestDelete) in C:\dev\xxxxx\NET3.0\NUnitTest\TestDAOUtil.cs:line 278<br />
at SimpleConsoleTest.Program.TestPeronDAO() in C:\dev\xxxxx\NET3.0\SimpleConsoleTest\Program.cs:line 131<br />
at SimpleConsoleTest.Program.Main() in C:\dev\xxxxx\NET3.0\SimpleConsoleTest\Program.cs:line 45<br />
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)<br />
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)<br />
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()<br />
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)<br />
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)<br />
at System.Threading.ThreadHelper.ThreadStart()<br />
{Inner Exception: NHibernate.ADOException: cannot open connection ---> System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.<br />
at System.Data.Common.UnsafeNativeMethods.OraMTSEnlCtxGet(Byte[] lpUname, Byte[] lpPsswd, Byte[] lpDbnam, OciHandle pOCISvc, OciHandle pOCIErr, UInt32 dwFlags, IntPtr& pCtxt)<br />
at System.Data.OracleClient.TracedNativeMethods.OraMTSEnlCtxGet(Byte[] userName, Byte[] password, Byte[] serverName, OciHandle pOCISvc, OciHandle pOCIErr, IntPtr& pCtxt)<br />
at System.Data.OracleClient.OciEnlistContext..ctor(Byte[] userName, Byte[] password, Byte[] serverName, OciServiceContextHandle serviceContextHandle, OciErrorHandle errorHandle)<br />
at System.Data.OracleClient.OracleInternalConnection.Enlist(String userName, String password, String serverName, Transaction transaction, Boolean manualEnlistment)<br />
at System.Data.OracleClient.OracleInternalConnection.Activate(Transaction transaction)<br />
at System.Data.ProviderBase.DbConnectionInternal.ActivateConnection(Transaction transaction)<br />
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)<br />
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)<br />
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)<br />
at System.Data.OracleClient.OracleConnection.Open()<br />
at NHibernate.Connection.DriverConnectionProvider.GetConnection()<br />
at NHibernate.Impl.SessionFactoryImpl.OpenConnection()<br />
--- End of inner exception stack trace ---<br />
at NHibernate.Impl.SessionFactoryImpl.OpenConnection()<br />
at NHibernate.AdoNet.ConnectionManager.GetConnection()<br />
at NHibernate.AdoNet.AbstractBatcher.Prepare(IDbCommand cmd)<br />
at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd)<br />
at NHibernate.Id.SequenceGenerator.Generate(ISessionImplementor session, Object obj)<br />
at NHibernate.Event.Default.AbstractSaveEventListener.SaveWithGeneratedId(Object entity, String entityName, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)<br />
at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)<br />
at NHibernate.Event.Default.DefaultSaveEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)<br />
at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.EntityIsTransient(SaveOrUpdateEvent event)<br />
at NHibernate.Event.Default.DefaultSaveEventListener.PerformSaveOrUpdate(SaveOrUpdateEvent event)<br />
at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent event)<br />
at NHibernate.Impl.SessionImpl.FireSave(SaveOrUpdateEvent event)<br />
at NHibernate.Impl.SessionImpl.Save(Object obj)<br />
<b>at xxxxx.Util.PersonDAO.Save(IGenericTO& oPerson) in C:\dev\xxxxx\NET3.0\Util\PersonDAO.cs:line 332 {Inner Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.</b><br />
at System.Data.Common.UnsafeNativeMethods.OraMTSEnlCtxGet(Byte[] lpUname, Byte[] lpPsswd, Byte[] lpDbnam, OciHandle pOCISvc, OciHandle pOCIErr, UInt32 dwFlags, IntPtr& pCtxt)<br />
at System.Data.OracleClient.TracedNativeMethods.OraMTSEnlCtxGet(Byte[] userName, Byte[] password, Byte[] serverName, OciHandle pOCISvc, OciHandle pOCIErr, IntPtr& pCtxt)<br />
at System.Data.OracleClient.OciEnlistContext..ctor(Byte[] userName, Byte[] password, Byte[] serverName, OciServiceContextHandle serviceContextHandle, OciErrorHandle errorHandle)<br />
at System.Data.OracleClient.OracleInternalConnection.Enlist(String userName, String password, String serverName, Transaction transaction, Boolean manualEnlistment)<br />
at System.Data.OracleClient.OracleInternalConnection.Activate(Transaction transaction)<br />
at System.Data.ProviderBase.DbConnectionInternal.ActivateConnection(Transaction transaction)<br />
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)<br />
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)<br />
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)<br />
at System.Data.OracleClient.OracleConnection.Open()<br />
at NHibernate.Connection.DriverConnectionProvider.GetConnection()<br />
at NHibernate.Impl.SessionFactoryImpl.OpenConnection()<br />
dev
|
|
|
|
|
I have created an application that seems to be using quite a bit amount of memory. This application contacts the SQL server quite often. It also using some simple threading. The thing is, I have closed everything that was ever opened and disposed it. Any threads being used have been disposed as well. This is why I am a little confused. After inserting pictures in this inventory application, after I was done, I looked in the task manager and the app was up over 300,000kb in memory usage. Now it seems I've looked over something on closing?
Or is C# slow at garbage collection?
|
|
|
|
|
I guess my question was is that a large amount or not? I mean 300mb seems large. I didn't wait long to see if it went down.
|
|
|
|
|
Hi,
Task Manager is not providing the right information. It shows how much memory an app is currently entitled to use, not how much is actually used. When a .NET app needs memory, it either looks for free memory inside the process, or asks Windows for more. When objects die, their memory is garbage collected but not necessarily returned to Windows.
One experiment you could do is this: minimize your main form, then watch Task Manager. The number will be lower now. If that reduced number stays somewhat constant over time (each time minimizing), then as a first approximation your app isn't loosing/wasting memory. If that number keeps growing, your app probably has some memory leaks.
I often include a permanent memory observer in the app itself: have a timer regularly update a label and have it show the value of Environment.WorkingSet (divide by 1024*1024 to get megabytes). That is more comfortable and more reliable than the TM numbers.
PS: large is a relative notion. If your system has ample memory and Windows is willing to give 500MB of memory to your app, then the app will use that to its advantage, i.e. the need to garbage collect will be reduced.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
So I open and close my window, looking to see if the memory usage gets smaller each time and stays constant?
I will try the WorkingSet tomorrow when I get to work and see how it does.
I know you have helped me before and I appreciate it!
|
|
|
|
|
Jacob Dixon wrote: So I open and close my window
actually minimize and restore.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Lol thats what I meant
Actually I use a notifyicon and when minimizing I hide the form and restore it with a doubleclick of the notifyicon (or right-click restore). I did find one memory leak. When loading the Inventory Form(the editing of an item part), I made it use threading to load the image (due to the fact that the image could take a while to load and I didn't want the whole form freezing at this time, this is only an issue when working remotely). Now I did notice that the thread still runs on exiting everything. So I need to abort that thread no matter what during the closing event right?
I'm still learning on the progressbar for reading using the sequentialaccess for the VARBINARY column. The problem is, I only see the SequentialAccess being used with the TEXT column (BLOB). I didn't use the TEXT column.
|
|
|
|
|
Hi Jacob,
yes tasks that may take several hundreds of milliseconds or more should not be organized on the main or GUI thread, since that adversely affects the GUI's responsiveness.
The solution basically is using a thread, i.e. either a Thread class instance, or a ThreadPool item, or a BackgroundWorker.
Threads are either foreground or background; background means they don't prevent your app from exiting. Therefore, real background stuff, things that are relevant to the user as long as the app is running, but not when the app stops, should be organized in a background thread. Then, an explicit abort is not needed. Aborting a thread can be messy, you don't know in general what exactly it is/was doing at the moment you issue the abort command, hence a lot of objects and resources could be in an unknown state.
BackgroundWorkers are always running in the background. ThreadPool threads are not, and should never be aborted (well aborting them on app exit may be OK).
Things that are important to finish, should not be run in background, e.g. a database update. You don't want your app to exit in the midst of a DB update, so you may have to take special precautions for that.
I can't help you with the VARBINARY stuff.
I am not sure what you want about the progress bar; in general operations that you order as a single command will not allow you to see any progress, they are either ongoing or done, without any intermediate quantization.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Ah the minimize trick, but I wonder, how would you do "the same" (force the program to release unused ram) for console apps and other programs without a window to minimize? Surely it's not the minimized state that is somehow magic but a call the framework does under the hood?
|
|
|
|
|
harold aptroot wrote: how would you do "the same"
I would not. As I said, when relevant, I install a label (*) that permanently shows the working set, and I don't minimize; I only tell the minimize trick to put people's mind at ease after they got worried by Task Manager.
(*) Actually, the label often is a status bar showing working set, number of GDI objects, current time, and whatever else I consider relevant.
Furthermore, I seldom use Console apps, when I do they are short, simple and short lived. And my windowless Windows apps have very constrained functionality and a very stable memory need.
Having a solid background in real-time and limited-resource systems, I tend to be aware of the objects I create; but then I seldom use third-party libraries, I oversee all the software on a system, and I don't just throw things around without caring at all.
Knowing the large-object-heap never gets compacted, I am fully aware the GC has its limitations, and you may well end up fragmenting your memory, so you may get an OutOfMemoryException even when Task Manager would tell you you are hardly using any memory at all.
For testing purposes, it makes a lot of sense to have a "fast forward" mode, where the app creates objects as intended, but speeds or skips its business logic, so you can simulate a long lasting exceution in a matter of minutes.
In the end, building a reliable and long-lived app with strong variations in memory needs remains a challenge under .NET
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Ok, then let me ask it like this, how should I do "the same"?
Putting peoples mind at ease is of course far more important than actual memory usage - they will believe TaskManager sooner than some label you put somewhere (it could be lying, right? and it's not in TaskManager's interest to do so - how many people don't think like this?)
I have a bit of a background in z80 assembly programming (TI 83/84 calcs during highschool), so I tend to be careful as well (except in my article, I just messed around there )
But I still want to know, you know, the minimize trick makes me curious as to how it manages to do whatever it is it's doing - and what is is doing? Forcing a GC? Releasing unused pages? Something else?
|
|
|
|
|