请帮助我使这段代码线程安全

我在使数据加载和过滤线程安全方面遇到了一些问题。 我的控件基类上的以下代码通过BackgroundWorker处理所有数据填充。 这往往会在“this.DataWorker.RunWorkerAsync()”上抛出错误,说明BackgroundWorker正忙。 /// /// Handles the population of the form data. /// /// Whether to pull data back from the WebService. public void Populate(bool reload) { if (!this.DataWorker.IsBusy) { // Disable the filter options IvdSession.Instance.FilterManager.SetEnabledState(this.GetType(), false); // Perform the population this.DataWorker.RunWorkerAsync(reload); } else if (!reload) { // If the data worker is busy and […]

LINQ查询列表中的列表

我有这种情况: 我的ModelView: public class Subject { public int ID { get; set; } public string Name { get; set; } public int ProfessorID { get; set; } public string ProfessorFullName{ get; set; } public IList Assistants { get; set; } } public class Assistant { public string AssistantFullName{ get; set; } } 我的查询: var subjects […]

for循环“索引超出范围”c#webdriver

我从这个循环得到“索引超出范围”。 但我需要使用循环创建的新元素,我该怎么做? 请帮助解决问题 int linkCount = driver.FindElements(By.CssSelector(“a[href]”)).Count; string[] links = new string[linkCount]; for (int i = 0; i < linkCount; i++) { List linksToClick = driver.FindElements(By.CssSelector(“a[href]”)).ToList(); links[i] = linksToClick[i].GetAttribute(“href”); }

Windows Phone Back KeyPress + MessageBox在没有选择的情况下崩溃应用程序

我有一个奇怪的问题,在代码后面覆盖BackkeyPress函数,在函数内部我有一个简单的消息框来返回或取消导航(保留在当前页面中),当没有选择(ok或取消)并且Messagebox长时间打开时间,应用程序崩溃,当我尝试调试时,没有exception被抛出并且App保持状态,除非按下OK或取消,但是在正常运行(没有调试器)时崩溃是显而易见的。 protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e) { string caption = “exit?”; string message = “Do you still want to exit?”; e.Cancel = MessageBoxResult.Cancel == MessageBox.Show(message, caption, MessageBoxButton.OKCancel); base.OnBackKeyPress(e); }

如何获得芒果的Carrier细节?

是否有任何API可以让我们的手机在哪个运营商(例如:沃达丰)? 母国,现在的国家,详情? 我在Microsoft.Phone.Net.NetworkInformation中找不到任何此类内容,我错过了什么? 感谢帮助。

如何将对象从帧传递到Windows 8样式应用程序中的另一个帧

我有问题,我现在无法弄清楚。 我正在尝试开发一个Windows-8风格的应用程序,并且我坚持实现这个function。 我有一个MainWindow ,它包含一个ListBox和一个Button(比如说addButton )。 当我单击按钮导航到新页面时,让我们说AddCustomerPage with this.Frame.Navigate(typeof(AddCustomerPage)); AddCustomerPage有1个textBox和1个按钮(比如doneButton 。当我点击按钮时,我希望textBox中的字符串被添加到上一页的ListBox中。 这是我目前的function:1。MainWindow已创建。 单击addButton AddCustomer页面已创建。 MainWindow被破坏(问题)。 点击doneButton 使用带有1个项目的ListBox创建MainWindow对象。 重复添加过程,我总是得到一个带有1个项目的ListBox的MainWindow。 谢谢您的帮助。 这是代码: public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); this.brainPageController = new PageController(); // add items from the List to the listBox listGoals.ItemsSource = brainPageController.GetListGoals(); } protected override void OnNavigatedTo(NavigationEventArgs e) { var […]

RSA Exception {“Bad Length。\ r \ n”} Noi Matter我的密钥大小是多少

我在行上收到运行时错误{“Bad Length。\ r \ n”}: return rsa.Encrypt(bytes, true); 这是在function: private static byte[] Encrypt(byte[] bytes) { using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider()) { string test = Properties.Settings.Default.PublicKeyXml; rsa.FromXmlString(“mfXS3Na0XfkjhpjS3sL5XcC9o+j6KXi1LB9yBc4SsTMo1Yk/pFsXr74gNj4aRxKB45+hZH/lSo933NCDEh25du1iMsaH4TGQNkCqi+HDLQjOrdXMMNmaQrLXGlY7UCCfFUnkEUxX51AlyVLzqLycaAt6zm5ljnDXojMC7JoCrTM=AQAB”); return rsa.Encrypt(bytes, true); } } 我使用的密钥大小为8192: CspParameters cspParams = new CspParameters(); cspParams.KeyContainerName = “XML_ENC_RSA_KEY”; RSACryptoServiceProvider rsaKey = new RSACryptoServiceProvider(8192, cspParams); string keyXml = rsaKey.ToXmlString(true); XML文件很小。 根据运行时的长度,它只有225个字节: string fileName […]

为每个页面刷新插入新行

嗨,我在将记录插入数据库时​​遇到了一个奇怪的问题。 在我的按钮单击事件中,我正在尝试将一些值插入到我的数据库中,它正常工作。 插入完成后……再次按下F5或刷新浏览器时,新行将插入表中的先前值。 为什么会这样? 谢谢

.NET Remotingexception未处理客户端

我检查了其余的远程问题,这个具体案例似乎没有得到解决。 我有一个.NET Remoting服务器/客户端设置。 在服务器端,我有一个对象,它有一个可以抛出exception的方法,以及一个尝试调用该方法的客户端。 服务器: public bool MyEquals(Guid myGuid, string a, string b) { if (CheckAuthentication(myGuid)) { logger.Debug(“Request for \”” + a + “\”.Equals(\”” + b + “\”)”); return a.Equals(b); } else { throw new AuthenticationException(UserRegistryService.USER_NOT_REGISTERED_EXCEPTION_TEXT); } } 客户: try { bool result = RemotedObject.MyEquals(myGuid, “cat”, “dog”); } catch (Services.Exceptions.AuthenticationException e) { Console.WriteLine(“You do not […]

将SecurePassword绑定到ViewModel

我尝试使用自定义Behavior将PasswordBox的SecurePassword属性绑定到我的ViewModel 。 可悲的是,它无法正常工作。 基本上我向Behavior添加了一个属性,其中包含我的ViewModel的target属性。 任何想法为什么它不起作用? PS:我目前正在回家的路上没有笔记本电脑,我将在大约15分钟内用我的代码更新问题。 但如果有人发表想法或某事,那会很好。 编辑 正如我所承诺的,这里有一些代码:) Behavior第一: using System; using System.Collections.Generic; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Windows.Interactivity; using System.Security; namespace Knerd.Behaviors { public class PasswordChangedBehavior : Behavior { protected override void OnAttached() { AssociatedObject.PasswordChanged += AssociatedObject_PasswordChanged; base.OnAttached(); } […]