Wpf / winforms C#和ASP.NET使用相同的DLL [英] Wpf/winforms C# and ASP.NET with the same DLL

查看:62
本文介绍了Wpf / winforms C#和ASP.NET使用相同的DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I'm doing a program that has to work in Wpf/Winforms c# and in asp.net c# calling a dll that is common to both technologies.

When I need the structure of general variables, which also contains the information of each user, a function that exists in the dll returns it by reference so that any change in a variable is available at the moment throughout the program. This now works well. But, in Asp.net i need the same function to return the structure by reference or by value, with the session saved with the variables of each user. If returned by reference like in WPF/Winforms, in Asp.net all users would share the same values.

namespace Name_Comun
{   public struct St_Comun
    {   public int User;
        public string Name;
    }

   public class Cls_Comun
   {   // Structure of general variables
       public static Name_Comun.St_Comun StComun;

       public Cls_Comun()
      {  Name_Comun.Cls_Comun.StComun = new Name_Comun.St_Comun();
      }
   }
}

public void Anyfunction()
{   // (At present). Retrieves by reference the structure with the general variables.
    ref Name_Comun.St_Comun StComun = ref Name_Comun.Cls_Comun.Fcn_StComunGet();

   // Change a variable. The variable is saved by reference.
   StComun.User = 100;

   // Save the changes. (In Wpf/Winforms not save anything because it is a reference). In Aspx save the Session["StComun"].
   Name_ComunAdd.Cls_ComunAdd.Fcn_StComunSet (ref StComun);
}

// Function that returns the structure with the general variables.
public static ref Fcn_StComunGet()
{   // Returns the address of the static variable.
    ref Name_Comun.St_Comun StComun = ref Name_Comun.Cls_Comun.StComun;

    // (It is not possible at this time). I NEED to return the Session for ref or value. Like: return ref Session["StComun"] or return Session["StComun"]
   if (Aplication == Aspx) StComun = ref Session["StComun"];
   return StComun;
}

public static void Fcn_StComunSet(ref Name_Comun.St_Comun StComun)
{ if (Aplication != Aspx) return;
  if (Aplication == Aspx) Session["StComun"] = StComun;
}

What I explain is that a function returns the structure of general variables as ref to be able to modify variables and that the changes in the rest of the program are accessible. But if it is Aspx, taking into account that a Session of the structure must be used for each user, I do not know how to do it for the same function to return it, since that function I use it hundreds of times in all my functions.

I NEED:
I need that if it is Aspx, the function public static function ref Fcn_StComunGet() returns something similar to return ref Session ["StComun"].

It also helps if you return return Session ["StComun"], but keep in mind that the function returns ref, not value, in case the program is not Aspx.

If is not possible return ref Session["Variable"] then I need the function to return Session["Variable"], but this function is also used in WPF/Winforms and is now returning ref. In this way, at the moment that I modify a variable, it is available without saving.





我尝试过:





What I have tried:

What have you tried

What have you tried

What have you tried

推荐答案





我不太确定我是否关注您,但如果您尝试同步数据并让客户端(Windows / Web / Services)获取更新,那么您可能需要重新考虑您的方法。 Web是无状态的,Sessions不可靠。您需要一个持久的数据存储(如数据库)来保存数据,而不是依赖于Sessions。有很多事情会导致会话状态神秘消失,其中包括:



(1)你的会话状态超时已经过期

(2)更新web.config或其他导致AppDomain回收的文件类型

(3)IIS中的AppPool回收

(4)您更新站点有很多文件,ASP.NET主动销毁你的AppDomain来重新编译和保存内存。



如果我是你,我会使用API​​ / WebService来托管数据,而不是使用类库/ DLL。这是您处理和管理数据库CRUD操作的地方。然后,API / WebService将充当您广播信息的中央网关,让您的WinForms和ASP.NET WebApps访问它以获取数据。
Hi,

I'm not quite sure if I follow you, but if you are trying to synchronize data and have the clients (Windows/Web/Services) get the updates, then you may want to rethink your approach. The Web is stateless and Sessions isn't reliable. You'd need a persistent data store such as a database to keep the data instead of relying to Sessions. There are a number of things that can cause Session state to mysteriously disappear which includes:

(1) Your Session State timeout has expired
(2) You update your web.config or other file type that causes your AppDomain to recycle
(3) Your AppPool in IIS recycles
(4) You update your site with a lot of files, and ASP.NET proactively destroys your AppDomain to recompile and preserve memory.

If I were you, I would use an API/WebService to host data instead of using a Class library/DLL. This is where you handle and manage database CRUD operations. The API/WebService will then act as your central gateway to broadcast information and have your WinForms and ASP.NET WebApps access to it to get the data.


I'm not talking about that. You have not understood the problem because you have to read it well and that takes time.

I raise my need to use a simple function that standardizes the return of a structure in ref mode to be able to modify variables at the moment and that are available in the rest of the program. I make a call to that function almost every function of the program, in hundreds of places.

It works well in WPF / WinForms but not in Asp.net, where there is a static dictionary that contains the information of each user's Session variables. To be able to return in ref mode, I need to be given the possibility to access that dictionary regardless of the duration of the information. If the information no longer exists, my function will create a new session.

Microsoft does not return that ref, so you can not standardize that pointer to the information, but that only happens in asp.net

Every time I find a precarious or serious failures in the code of Microsoft and I indicate it to him, the deaf ones become or they respond of arrogant form saying that I consider my program of another form. The serious errors that I have found do not correct them.

I have been working on something for a long time and serious failures in Sql Server are hurting me without Microsoft taking charge and nobody does anything:
Sql Server 2017 with Transact and synonyms Problems. Microsoft does not respond.

https://social.msdn.microsoft.com/Forums/en-US/6e1cb5ed-60fb-4d27-af97-9d31c8691139/sql-server-2017-with-transact-and-synonyms-problems-microsoft-does-not-respond?forum=transactsql

I do not want to extend more.


这篇关于Wpf / winforms C#和ASP.NET使用相同的DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆